slu182

GridView分页操作

1.html

                            <PagerStyle HorizontalAlign="Center" />
                            <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" Visible=\'<%#((GridView)Container.NamingContainer).PageIndex != 0 %>\'>首页</asp:LinkButton>

                                <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
                                    Visible=\'<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>\'>上一页</asp:LinkButton>

                                <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
                                    Visible=\'<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>\'>下一页</asp:LinkButton>

                                <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
                                    Visible=\'<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>\'>尾页</asp:LinkButton>
                                转到第<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text=\'<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>\' />
                                页        
                                    <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO" />
                            </PagerTemplate>

2.后台代码

        protected void gvAuthManagement_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView theGrid = sender as GridView;
            int newPageIndex = 0;
            if (e.NewPageIndex == -2)
            {
                TextBox txtNewPageIndex = null;
                GridViewRow pagerRow = theGrid.BottomPagerRow;
                if (pagerRow != null)
                {
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
                }
                if (txtNewPageIndex != null)
                {
                    newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
                }
            }
            else
            {
                newPageIndex = e.NewPageIndex;
            }
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
            theGrid.PageIndex = newPageIndex;
            InfoList = AuthorizationBiz.Query(new AuthorizationInfo());
            Bind(InfoList);
        }

 

发表于 2015-01-29 10:10  slu182  阅读(112)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-11-21
  • 2021-09-15
  • 2022-12-23
  • 2021-09-15
  • 2022-03-08
  • 2021-11-11
猜你喜欢
  • 2021-11-11
  • 2021-11-21
  • 2021-11-06
  • 2022-01-06
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案