熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 7.6 多個數據控件一起工作[2]

2022-06-13   來源: .NET編程 

    ()打開DataSourceControl (由DataList控件使用)的智能任務面板並啟動它的Configure Data Source向導步進到創建W HERE子句的對話框設置FixtureID的Column使其等於DropDownListl的ControlID默認值為不要忘記單擊Add按鈕單擊OK單擊Next結束這個過程然後測試查詢(參數值為l時正常)結束當出現提示時刷新該數據綁定控件您將在浏覽器中看到結果(雖然所有根據日期顯示的圖片都是第一場比賽的圖片)Source View中的代碼如下所示

 

<%@ Page Language=VB MasterPageFile=~/sitemaster AutoEventWireup=false CodeFile=Fixturesaspxvb Inherits=Fixtures title=Untitled Page %>

<asp:Content ID=Content ContentPlaceHolderID=MainContent Runat=Server>

<div style=float:left>

    <asp:GridView ID=GridView runat=server AutoGenerateColumns=False DataKeyNames=FixtureID

        DataSourceID=SqlDataSource EmptyDataText=There are no data records to display>

        <Columns>

            <asp:CommandField ShowSelectButton=True />

            <asp:BoundField DataField=FixtureID HeaderText=FixtureID ReadOnly=True SortExpression=FixtureID />

            <asp:BoundField DataField=FixtureDate HeaderText=FixtureDate SortExpression=FixtureDate />

            <asp:BoundField DataField=Opponents HeaderText=Opponents SortExpression=Opponents />

        </Columns>

    </asp:GridView>

    <asp:SqlDataSource ID=SqlDataSource runat=server ConnectionString=<%$ ConnectionStrings:WroxUnitedConnectionString %>

        DeleteCommand=DELETE FROM [Fixtures] WHERE [FixtureID] = @FixtureID InsertCommand=INSERT INTO [Fixtures] ([FixtureDate] [Opponents]) VALUES (@FixtureDate @Opponents)

        ProviderName=<%$ ConnectionStrings:WroxUnitedConnectionStringProviderName %>

        SelectCommand=SELECT [FixtureID] [FixtureDate] [Opponents] FROM [Fixtures]

        UpdateCommand=UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate [Opponents] = @Opponents WHERE [FixtureID] = @FixtureID>

        <InsertParameters>

            <asp:Parameter Name=FixtureDate Type=DateTime />

            <asp:Parameter Name=Opponents Type=String />

        </InsertParameters>

        <UpdateParameters>

            <asp:Parameter Name=FixtureDate Type=DateTime />

            <asp:Parameter Name=Opponents Type=String />

            <asp:Parameter Name=FixtureID Type=Int />

        </UpdateParameters>

        <DeleteParameters>

            <asp:Parameter Name=FixtureID Type=Int />

        </DeleteParameters>

    </asp:SqlDataSource>

    <asp:DetailsView ID=DetailsView runat=server AutoGenerateRows=False DataKeyNames=FixtureID

        DataSourceID=SqlDataSource Height=px Width=px>

        <Fields>

            <asp:BoundField DataField=FixtureID HeaderText=FixtureID InsertVisible=False

                ReadOnly=True SortExpression=FixtureID />

            <asp:BoundField DataField=FixtureDate HeaderText=FixtureDate SortExpression=FixtureDate />

            <asp:BoundField DataField=FixtureType HeaderText=FixtureType SortExpression=FixtureType />

            <asp:BoundField DataField=GoalsFor HeaderText=GoalsFor SortExpression=GoalsFor />

            <asp:BoundField DataField=GoalsAgainst HeaderText=GoalsAgainst SortExpression=GoalsAgainst />

            <asp:BoundField DataField=Notes HeaderText=Notes SortExpression=Notes />

            <asp:BoundField DataField=Opponents HeaderText=Opponents SortExpression=Opponents />

        </Fields>

    </asp:DetailsView>

    <asp:SqlDataSource ID=SqlDataSource runat=server ConnectionString=<%$ ConnectionStrings:WroxUnitedConnectionString %>

        SelectCommand=SELECT * FROM [Fixtures] WHERE ([FixtureID] = @FixtureID)>

        <SelectParameters>

            <asp:ControlParameter ControlID=GridView Name=FixtureID PropertyName=SelectedValue

                Type=Int />

        </SelectParameters>

    </asp:SqlDataSource>

    <asp:TreeView ID=TreeView runat=server DataSourceID=ScheduleXML>

        <DataBindings>

            <asp:TreeNodeBinding DataMember=Game TextField=#Value />

            <asp:TreeNodeBinding DataMember=Home TextField=#InnerText />

            <asp:TreeNodeBinding DataMember=Date TextField=#InnerText />

            <asp:TreeNodeBinding DataMember=Visitor TextField=#InnerText />

        </DataBindings>

    </asp:TreeView>

    <asp:XmlDataSource ID=ScheduleXML runat=server DataFile=~/Schedulexml>

    </asp:XmlDataSource>

</div>

</asp:Content>

[]  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15200.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.