天天看點

gridview分頁的實作

//實作分頁

AollowPaging = "true"

//分頁資料設定

PageSize = "10"

//分頁時觸發事件

OnPageIndexChanging = "gv_List_PageIndexChanging"

//這裡我給出一個通用顯示分頁的模闆(網上搜的)

<PagerTemplate>

目前第:

//((GridView)Container.NamingContainer)就是為了得到目前的控件

<asp:Label ID="lab_CurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>

頁/共:

//得到分頁頁面的總數

<asp:Label ID="lab_PageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>

//如果該分頁是首分頁,那麼該連接配接就不會顯示了.同時對應了自帶識别的指令參數CommandArgument

<asp:LinkButton ID="btn_FirstPage" runat="server" CommandArgument="First" CommandName="Page"

Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首頁</asp:LinkButton>

<asp:LinkButton ID="btn_PreviousPage" runat="server" CommandArgument="Prev"

CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一頁</asp:LinkButton>

//如果該分頁是尾頁,那麼該連接配接就不會顯示了

<asp:LinkButton ID="btn_NextPage" runat="server" CommandArgument="Next" CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一頁</asp:LinkButton>

<asp:LinkButton ID="btn_LastPage" runat="server" CommandArgument="Last" CommandName="Page"

Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾頁</asp:LinkButton>

轉到第

<asp:TextBox ID="txt_NewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />頁

//這裡将CommandArgument即使點選該按鈕e.newIndex 值為3

<asp:LinkButton ID="btn_Go" runat="server" CausesValidation="False" CommandArgument="-2"

CommandName="Page" Text="GO" />

</PagerTemplate>

繼續閱讀