<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后要获取文本框里面的值,根据值跳转到GridView中指定的页! 帮忙`````````` 在源代码上修改!

解决方案 »

  1.   

    在 Go 这个按钮的服务器端事件中,直接绑定数据源,然后设置 GridView 的 PageIndex 值即可!
      

  2.   

    GridViewRow pagerRow = GridView1.BottomPagerRow;
    TextBox pageNum = (TextBox)pagerRow.Cells[0].FindControl("tbpage");
      

  3.   

    有道理,只要能读到PageIndex就好了
      

  4.   

     <PagerTemplate> 
                <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First" Enabled="false" 
                    CommandName="Page">首页 </asp:LinkButton> 
                <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev" Enabled="false"
                    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="Pageindex" Text="GO"> </asp:LinkButton> 
                </PagerTemplate> 
    CS代码:
        protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Pageindex")
            {
               TextBox tb=GridView1.BottomPagerRow.FindControl("tbPage") as TextBox;
               int pageindex = Convert.ToInt32(tb.Text);
               GridView1.PageIndex = pageindex-1;
               GridView1.DataSource = (DataView)Session["temp"];
               GridView1.DataBind();
            }
        }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {        GridView1.PageSize = 4;
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource=(DataView)Session["temp"];
            GridView1.DataBind();
        }这样就可以了
      

  5.   

     <PagerTemplate> 
                <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First" Enabled="false" 
                    CommandName="Page">首页 </asp:LinkButton> 
                <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev" Enabled="false"
                    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="Pageindex" Text="GO"> </asp:LinkButton> 
                </PagerTemplate> 
    CS代码:
        protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Pageindex")
            {
               TextBox tb=GridView1.BottomPagerRow.FindControl("tbPage") as TextBox;
               int pageindex = Convert.ToInt32(tb.Text);
               GridView1.PageIndex = pageindex-1;
               GridView1.DataSource = (DataView)Session["temp"];
               GridView1.DataBind();
            }
        }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {        GridView1.PageSize = 4;
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource=(DataView)Session["temp"];
            GridView1.DataBind();
        }这样就可以了
      

  6.   

    前台代码跟你一样,只是改了             <asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="-1" 
                CommandName="Pageindex" Text="GO"> </asp:LinkButton> 
    这里的CommandName="Pageindex"
    Session里存的是数据
      

  7.   

    <asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="-1" 
    CommandName="Page" Text="GO" OnClick="GoIndex"> </asp:LinkButton>//添加对lbGO单击事件
    protected void GoIndex(object sender, EventArgs e)
    {
            GridViewRow pagerRow = GridView1.BottomPagerRow;
            TextBox pageNum = pagerRow.Cells[0].FindControl("tbpage") as TextBox;
            if(pageNum.Text!=null)
            GridView1.PageIndex = Convert.ToInt32(pageNum.Text)-1;
    }protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       if(e.NewPageIndex>=0&&e.NewPageIndex<GridView1.PageCount)
            GridView1.PageIndex = e.NewPageIndex;
       gview_bind();  //绑定数据源
    }这样就可以了