前台代码:     <PagerTemplate>
   <div style=" float:right;">
         <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
         <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"  Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>
        <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev"  ></asp:LinkButton>
        <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>
         <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"   Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>
         到第<asp:TextBox runat="server" ID="inPageNum" Width="20px"></asp:TextBox>页 <asp:ImageButton  ID="btnGo" ImageUrl ="images/fdj.gif"  runat="server" CommandName="Page" CommandArgument="Prev" />
         <br />
     </div>
   </PagerTemplate>
后台代码
protected void gvLog_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "goPage")
        {
                TextBox tb = (TextBox)gvLog.BottomPagerRow.FindControl("inPageNum");
                int num = Int32.Parse(tb.Text);
                GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1);
                result_PageIndexChanging(null, ea);
        }
    }
现在出现的问题是当点击首页,上一页,下一页,尾页都没问题,但是点击跳转页时无法跳转,调试后发现当点击跳转页时就没有执行到后台代码。各位帮忙看看这是啥情况

解决方案 »

  1.   

    if (e.CommandName == "goPage")<asp:ImageButton  ID="btnGo" ImageUrl ="images/fdj.gif"  runat="server" CommandName="Page" CommandArgument="Prev" />
      

  2.   


    真不好意思,贴错代码了,上面的修改是为了找问题原因的~<PagerTemplate>
       <div style=" float:right;">
             <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
             <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"  Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>
            <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev"  ></asp:LinkButton>
            <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>
             <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"   Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>
             到第<asp:TextBox runat="server" ID="inPageNum" Width="20px"></asp:TextBox>页 <asp:ImageButton  ID="btnGo" ImageUrl ="images/fdj.gif"  runat="server" CommandName="goPage"  />
             <br />
         </div>
       </PagerTemplate>
      

  3.   

    http://zhangruidq.blog.163.com/blog/static/56083551200711169443360/
      

  4.   

    if (e.CommandName == "goPage")这一行走了没?跳转到第几页 应该就不在Gridview 里了 前 后 首 末  完全可以不用RowCommand事件简单的
    vsiable属性!!!!!!!
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
               }
        public void bind()
        {
            SqlConnection cn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=sa");
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from authors", cn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            cn.Close();
            GridView1.DataSource = ds;
            GridView1.AllowPaging = true;
            GridView1.PageSize = 5;
            GridView1.DataBind();
            if (GridView1.PageIndex == 0)
            {
                Button1.Enabled = false;
                Button2.Enabled = false;
            }
            else
            {
                Button1.Enabled = true;
                Button2.Enabled = true;
            }
            if (GridView1.PageIndex == GridView1.PageCount - 1)
            {
                Button3.Enabled = false;
                Button4.Enabled = false;
            }
            else
            {
                Button3.Enabled = true;
                Button4.Enabled = true;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
          
            GridView1.PageIndex = 0;
            bind();
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = GridView1.PageIndex + 1;
            bind();
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = GridView1.PageCount - 1;
            bind();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            GridView1.PageIndex = GridView1.PageIndex - 1;
            bind();
        }
    }
    分页控件例子
      

  5.   

    本帖最后由 net_lover 于 2011-07-05 13:08:49 编辑