结果如下代码所示
<%@ Page Language=VB MasterPageFile=~/sitemaster AutoEventWireup=false CodeFile=FixturesStackedaspxvb Inherits=Fixtures_Stacked title=Untitled Page %>
<asp:Content ID=Content ContentPlaceHolderID=mainContent Runat=Server>
<asp:DetailsView ID=DetailsView runat=server AllowPaging=True AutoGenerateRows=False
DataKeyNames=FixtureID DataSourceID=SqlDataSource Height=px Width=px>
<PagerSettings FirstPageText=First Game of the Season LastPageText=Last Game of the Season
Mode=NumericFirstLast />
<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]></asp:SqlDataSource>
</asp:Content>
()在浏览器中运行该页面以观察每次只显示一场比赛
操作回顾
这个练习的关键是创建和查看每次只显示一条记录的页面就像查看一叠卡片中最上面的那一张可以使用DetailsView或FormView选择Detai is View是因为它有一个自动的默认布局
对DetailsView控件所做的修改与在前面的练习中对其他数据绑定控件所做的修改几乎是一样的为了在比赛的记录之间移动可以通过勾选该控件的智能任务面板中恰当的复选框激活分页功能为了增强用户的体验可以在该控件的Properties窗口中指定了一组特定的导航工具并修改它们的文本以便提供一个更加符合逻辑的用户界面
ASPNET 入门教程完整版
[] []