FormView中的PagerTemplate的使用
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
<title>GridView DetailsView Master-Details (with Editing)</title>
</head>
<script runat="server">
protected void FormView1_DataBound(object sender, EventArgs e)
{
//注意是在BottomPagerRow中,
if ((FormView1.PageIndex + 1) == FormView1.PageCount)
{
((Button)FormView1.BottomPagerRow.FindControl("Last")).Enabled = false;
((Button)FormView1.BottomPagerRow.FindControl("Next")).Enabled = false;
}
if (FormView1.PageIndex == 0)
{
((Button)FormView1.BottomPagerRow.FindControl("First")).Enabled = false;
((Button)FormView1.BottomPagerRow.FindControl("Prev")).Enabled = false;
}
}
</script>
<html>
<head id="Head1" runat="server">
<title>GridView DetailsView Master-Details (with Editing)</title>
</head>
<script runat="server">
protected void FormView1_DataBound(object sender, EventArgs e)
{
//注意是在BottomPagerRow中,
if ((FormView1.PageIndex + 1) == FormView1.PageCount)
{
((Button)FormView1.BottomPagerRow.FindControl("Last")).Enabled = false;
((Button)FormView1.BottomPagerRow.FindControl("Next")).Enabled = false;
}
if (FormView1.PageIndex == 0)
{
((Button)FormView1.BottomPagerRow.FindControl("First")).Enabled = false;
((Button)FormView1.BottomPagerRow.FindControl("Prev")).Enabled = false;
}
}
</script>
<body>
<form id="form1" runat="server">
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="au_id" DataSourceID="SqlDataSource5" AllowPaging="True" OnDataBound="FormView1_DataBound" >
<ItemTemplate>
au_id:
<asp:Label ID="au_idLabel" runat="server" Text='<%# Eval("au_id") %>'></asp:Label><br />
<br />
</ItemTemplate>
<PagerTemplate>
<asp:Button ID="First" runat="server" Text="First" CommandArgument="First" CommandName="Page" />
<asp:Button ID="Prev" runat="server" CommandArgument="Prev" CommandName="Page"
Text="Prev" />
<asp:Button ID="Next" runat="server" Text="Next" CommandName="Page" CommandArgument="Next" />
<asp:Button ID="Last" runat="server" Text="Last" CommandArgument="Last" CommandName="Page" />
</PagerTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:Pubs %>"
SelectCommand="SELECT * FROM [authors]"></asp:SqlDataSource>
</form>
</body>
</html>
<form id="form1" runat="server">
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="au_id" DataSourceID="SqlDataSource5" AllowPaging="True" OnDataBound="FormView1_DataBound" >
<ItemTemplate>
au_id:
<asp:Label ID="au_idLabel" runat="server" Text='<%# Eval("au_id") %>'></asp:Label><br />
<br />
</ItemTemplate>
<PagerTemplate>
<asp:Button ID="First" runat="server" Text="First" CommandArgument="First" CommandName="Page" />
<asp:Button ID="Prev" runat="server" CommandArgument="Prev" CommandName="Page"
Text="Prev" />
<asp:Button ID="Next" runat="server" Text="Next" CommandName="Page" CommandArgument="Next" />
<asp:Button ID="Last" runat="server" Text="Last" CommandArgument="Last" CommandName="Page" />
</PagerTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:Pubs %>"
SelectCommand="SELECT * FROM [authors]"></asp:SqlDataSource>
</form>
</body>
</html>