html
<PagerTemplate>
      <table>
        <tr>
          <td style="text-align: right"> 第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>
              页 共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>
              页
           <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" Text="首页"></asp:LinkButton>
          <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
          CommandName="Page" Text="上一页"></asp:LinkButton>
           <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
            CommandName="Page" Text="下一页"></asp:LinkButton>
             <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
            CommandName="Page" Text="尾页"></asp:LinkButton>
          <asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox>
          <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO"></asp:LinkButton>
         </td>
      </tr>
    </table>
</PagerTemplate>cs
 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView gvw = (GridView)sender;
        if (e.NewPageIndex < 0)
        {
            TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex");
            int Pa = int.Parse(pageNum.Text);
            if (Pa <= 0)
            {
                gvw.PageIndex = 0;
            }
            else
            {
                gvw.PageIndex = Pa - 1;
            }
        }
        else
        {
            gvw.PageIndex = e.NewPageIndex;
        }
        gvw.DataBind();
    }式样
第1 页 共13 页 首页 上一页 下一页 尾页 1  GO 问题
其他按钮都正常,就是我在红色字体中输入页数,无法跳转。
跟踪代码,发现pageNum.Text的值永远是1。
请问大家这是为什么啊?
另外Page_Load中直接显示griview,没有使用ispostback。

解决方案 »

  1.   

    你在上面没有加 if (!Page.IsPostBack)
            {
               Binddata()      
            }
     protected void Binddata()
    {
        绑定datagridview
    }可能是这样,   你在每点GO的时候,  都会刷新页面, 这时候pageNum.Text就归1了, 你加上这个,然后把绑定单独提出来。 。   
      

  2.   


    可是,如果加了ispostback,我浏览后面几页就无法显示了。
    求解
      

  3.   

    你注意啊,你的这个页面跳转是通过点击GO按钮实现的,你的GO按钮是一个LinkButton
    <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO"></asp:LinkButton>这个LinckButton的事件你是怎么处理的???
      

  4.   

    CommandName="Prev"、"Next"他会帮去自动换页?CommandName="Page"?我觉得不可能有作用的,需要你在代码里面取得TextBox里面的页码值赋个GridView的CurrentPageIndex。
      

  5.   

    4#你说后面不好使 是指什么 是点GO 不好使, 还是点上一页, 下一页啊,  描述下被,而且我也没看你写LinckButton事件啊