asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET入门教程 7.6 多个数据控件一起工作[2]


发布日期:2019年10月12日
 
ASP.NET入门教程 7.6 多个数据控件一起工作[2]

)打开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>

[] [] []

               

上一篇:ASP.NET入门教程 7.6 多个数据控件一起工作[1]

下一篇:ASP.NET入门教程 9.5 变量的作用域和生存期