一个简单的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();
??? }
轉載于:https://www.cnblogs.com/gjwolf/archive/2012/04/27/2473630.html
總結
以上是生活随笔為你收集整理的一个简单的GridView分页的全部內容,希望文章能夠幫你解決所遇到的問題。