<PagerTemplate> 
<asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First" 
CommandName="Page">首页</asp:LinkButton> 
<asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev" 
CommandName="Page">上一页</asp:LinkButton> 
<asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next" 
CommandName="Page">下一页</asp:LinkButton> 
<asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last" 
CommandName="Page">尾页</asp:LinkButton> 第<asp:Label ID="Label2" 
runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页 
共<asp:Label ID="Label1" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页 
跳到<asp:TextBox ID="tbPage" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>" 
Width="27px"></asp:TextBox> 
<asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="-1" 
CommandName="Page" Text="GO"></asp:LinkButton> 
</PagerTemplate> 
分页事件
    protected void borrowGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView gvw = (GridView)sender;        if (e.NewPageIndex < 0)
        {
            TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("tbpage");            int Pa = int.Parse(pageNum.Text);
            if (Pa <= 0)
                gvw.PageIndex = 0;
            else
                gvw.PageIndex = Pa - 1;        }
        else
        {
            gvw.PageIndex = e.NewPageIndex;
        }        borrowGridView.DataSource = sa.selAssertBorrow();
        borrowGridView.DataBind();
    }
    首页 上一页 下一页 尾页 第?页 共?页 跳到?页GO
帮忙修改一下代码,要实现在第一页的时候"首页"和"上一页"不可用,在最后一页的时候"尾页"和"下一页"不可用,点GO的时候不能跳到要指定到的页。 谢谢拉!

解决方案 »

  1.   

    <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First" 
    CommandName="Page" Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页 </asp:LinkButton> 
    <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev" 
    CommandName="Page" Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页 </asp:LinkButton> 
    <asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next" 
    CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页 </asp:LinkButton> 
    <asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last" 
    CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页 </asp:LinkButton>
     
      

  2.   

    很少有人用GridView自带的分页了..
      

  3.   

    给按钮加个CommandName,值设置为“Jump”什么的,在分页事件面判断这个值e.CommandName=="Jump"就按照输入的页数进行翻页。OK!
    不过现在都流行自定义分页控件了。呵呵,自己写一个吧!
      

  4.   

     把我写的代码放在if (e.NewPageIndex < 0) 里
      

  5.   

    会报错误,
    提示上下文中找不到pagerRow的定义!