GridView里添加复选款和分页功能

2/10/2017来源:ASP.NET技巧人气:862

  <asp:GridView ID="post_gv" runat="server" DataKeyNames="VirId" AutoGenerateColumns="False" ClientIDMode="Static"  AllowPaging="True"           PageSize="5" OnPageIndexChanging="post_gv_PageIndexChanging"  >

        <Columns>

//下面是复选款

            <asp:TemplateField>                  <HeaderTemplate>                     <asp:CheckBox ID="SelAll" runat="server" Text="全选"  />                 </HeaderTemplate>                 <ItemTemplate>                     <asp:CheckBox ID="Sel" runat="server" />                 </ItemTemplate>             </asp:TemplateField> //下面是绑定数据源             <asp:BoundField  DataField="VirPostTitel" HeaderText="标题"/>             <asp:BoundField  DataField="VirPostContent" HeaderText="内容"/>             <asp:BoundField  DataField="VirUserName" HeaderText="作者"/>              <asp:BoundField  DataField="VirPublishedTime" HeaderText="时间"/>

        </Columns>

//下面是分页设置

                    <PagerTemplate>                 <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"                     Visible='True' CSSClass="pTemplate">首页</asp:LinkButton>                 <asp:LinkButton ID="LinkButtonPReviousPage" runat="server" CommandArgument="Prev"                     CommandName="Page" Visible='True' CssClass="pTemplate" >上一页</asp:LinkButton>                 <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"                     Visible='True' CssClass="pTemplate">下一页</asp:LinkButton>                 <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"                     Visible='True' CssClass="pTemplate">尾页</asp:LinkButton>                      当前第:                 <asp:Label ID="LabelCurrentPage1" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>" CssClass="LabelCurrentPage1" ClientIDMode="Static"></asp:Label>                 页/共:                 <asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>                 页             </PagerTemplate>     </asp:GridView>