一个简单的GridView分页
在GridView里面加上
<PagerTemplate>
<asp:LinkButton ID="FirstPage" runat="server" CommandName="Page" CommandArgument="First" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="PreviewPage" runat="server" CommandArgument="Prev" CommandName="Page" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="NextPage" runat="server" CommandName="Page" CommandArgument="Next" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">
下一页</asp:LinkButton>
<asp:LinkButton ID="LastPage" runat="server" CommandName="Page" CommandArgument="Last" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>第<asp:Label ID="lblcurPage" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1%>'></asp:Label>页/共
<asp:Label ID="lblPageCount" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页
<asp:TextBox ID="txtGo" runat="server" Width="30px" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:TextBox>页
<asp:Button ID="btnTurn" runat="server" Text="转到" OnClick="btnTurn_Click" />
</PagerTemplate>
编辑模板双击Button在后台代码:
protected void btnTurn_Click(object sender, EventArgs e)
{
GrvInquires.PageIndex = int.Parse(((TextBox)GrvInquires.BottomPagerRow.FindControl("txtGo")).Text) - 1;
MyDataBind();
}