ในการแสดงข้อมูล เช่น จำนวนหน้าทั้งหมดในหน้าเพจ
เราจะใช้ <PagerTemplate>
ดังตัวอย่างต่อไปนี้
<asp:GridViewID="GridView1"runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="ID"
AllowPaging="true"
PageSize="10"
AutoGenerateColumns="true">
<PagerTemplate>
<asp:LabelID="LabelCurrentPage"runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageIndex
+ 1 %>">
</asp:Label>/
<asp:LabelID="LabelPageCount"runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageCount
%>">
</asp:Label>
<asp:LinkButtonID="LinkButtonFirstPage"runat="server"
CommandArgument="First"
CommandName="Page"
enabled="<%# ((GridView)Container.NamingContainer).PageIndex
!= 0
%>"><<
asp:LinkButton
ID="LinkButtonPreviousPage"runat="server"
CommandArgument="Prev"CommandName="Page"
enabled="<%#((GridView)Container.NamingContainer).PageIndex
!= 0 %>"><
</asp:LinkButton>
<asp:LinkButtonID="LinkButtonNextPage"runat="server"
CommandArgument="Next"
CommandName="Page"
enabled="<%#((GridView)Container.NamingContainer).PageIndex
!=
((GridView)Container.NamingContainer).PageCount - 1
%>">>
</asp:LinkButton>
<asp:LinkButtonID="LinkButtonLastPage"runat="server"
CommandArgument="Last"
CommandName="Page"
enabled="<%#((GridView)Container.NamingContainer).PageIndex
!=
((GridView)Container.NamingContainer).PageCount - 1
%>">>>
</asp:LinkButton>
</PagerTemplate>
</asp:GridView>
Supa Sethasiripong [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.