关键代码如下:
aspx页面<asp:gridview id="GridView1" runat="server" allowpaging="True" pagesize="10"
            onpageindexchanging="GridView1_PageIndexChanging">
            <columns>
………………
            </columns>
               <pagertemplate>
                <div>                                        
                 <asp:textbox id="txtNewPageIndex" runat="server" width="20px"  />//此textbox 输入想去的第几页
                 <asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="确定"/>//点击确定,触发后台的跳转动作
                </div>
            </pagertemplate>
        </asp:gridview> 
aspx.cs文件
    protected void Page_Load(object sender, EventArgs e)
    {
      //绑定数据给GridView1
    }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (-2 == e.NewPageIndex) { // 点了确定触发
         string n=((TextBox)GridView1.BottomPagerRow.FindControl("txtNewPageIndex")).Text;//此处错误,无论怎么样处理,始终得到的是空值,不是null,是"",没有得到输入的值         
         GridView1.PageIndex = int.Parse(n) - 1;
         this.GridView1.DataBind();
        }
    }我找网上找了些例子,都是这个样子的,为什么我就无法得到输入的值,请教各位,谢谢!

解决方案 »

  1.   

    我好像没太理解
      LZ 你想要实现 什么样的跳转?
    是gridview 的点击列链接 到另外一个画面  还是 什么???
      

  2.   

    你没必要把跳转放到pageindexchanging事件里面把。
    另外用个按钮,然后在该按钮的click事件里面设置页面跳转就行了啊。
    protected void btnGo_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = Convert.ToInt32(txtNewPageIndex) - 1;
        }
      

  3.   

    这样取值始终是string.Empty的,你可以这样嘛
    if(!Page.IsPostBack)
    {
        int index = int.Parse(this.txtNewPageIndex.Text.Trim());
        bindData(index);
    }...
    public void bindData(int id)
    {
       ...
    }
      

  4.   


    不好意思。这里txtNewPageIndex改为txtNewPageIndex.Text。
    另外你自己判断下txtNewPageIndex.Text值的有效性(必须为自然数)。