Gridview 绑定自定义页面模板

要在页脚显示如总页数的信息,你可以用<PagerTemplate>项,如下例所示:

 

<asp:GridView ID="GridView1" runat="server"

    DataSourceID="SqlDataSource1"

    DataKeyNames="ID"

    AllowPaging="true"

   PageSize="10"

    AutoGenerateColumns="true">

<PagerTemplate>

    <asp:Label ID="LabelCurrentPage" runat="server"

        Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>">

    </asp:Label>/

    <asp:Label ID="LabelPageCount" runat="server"

       Text="<%# ((GridView)Container.NamingContainer).PageCount %>">

    </asp:Label>

    <asp:LinkButton ID="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:LinkButton ID="LinkButtonNextPage" runat="server"

        CommandArgument="Next"

        CommandName="Page"

        enabled="<%# ((GridView)Container.NamingContainer).PageIndex !=

            ((GridView)Container.NamingContainer).PageCount - 1 %>">>

    </asp:LinkButton>

    <asp:LinkButton ID="LinkButtonLastPage" runat="server"

        CommandArgument="Last"

        CommandName="Page"

        enabled="<%# ((GridView)Container.NamingContainer).PageIndex !=

         ((GridView)Container.NamingContainer).PageCount - 1 %>">>>

    </asp:LinkButton>

</PagerTemplate>

</asp:GridView>

 

 

你可能感兴趣的:(GridView)