我的分页点了以后不管用。不显示下一页。还在本页。
代码如下:
BindGrid类代码:using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;/// <summary>
/// BindGrid 的摘要说明
/// </summary>
public class BindGrid
{
    public SqlConnection con;
    public SqlDataAdapter sda;
    public DataSet ds;
    //public BindGrid(string sql_select) 
    //{
    //    con = new SqlConnection(ConfigurationSettings.AppSettings["Str_sql"]);
    //    con.Open();
    //    sda = new SqlDataAdapter(sql_select, con);
    //    ds = new DataSet();
    //    sda.Fill(ds);
    //    //
    //    // TODO: 在此处添加构造函数逻辑
    //    //
    //}
    public BindGrid()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public void Opencon(string sql_select)
    {
        con = new SqlConnection(ConfigurationSettings.AppSettings["Str_sql"]);
        con.Open();
        sda = new SqlDataAdapter(sql_select, con);
        BindGrid1(sda);
    }
    public void BindGrid1(SqlDataAdapter sda)
    {
        ds = new DataSet();
        sda.Fill(ds);
    }
    public void NextGrid1(DataSet ds)
    {
        
    }
}cs代码:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_cus_manage_invete_ratify : System.Web.UI.Page
{
    protected string sql_select, str_where;
    protected SqlCommand cmd_updata;
    protected BindGrid Bgrid;
    protected void Page_Load(object sender, EventArgs e)
    {
        sql_select = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication='n'";
        Bgrid = new BindGrid();
        Bgrid.Opencon(sql_select);
        if (!IsPostBack)                                        // 第一个加载的时候绑订datagrid
        {            Bgrid.BindGrid1(Bgrid.sda);
            DataGrid1.DataSource = Bgrid.ds.Tables[0];
            DataGrid1.DataBind();        }        ShowStats();
        Bgrid.con.Close();    }    protected void Button1_Click1(object sender, EventArgs e)
    {
        str_where = Request.Form.Get("titxt_gjz").ToString();          // 按查询条件绑订datagrid
        if (str_where != "")
        {
            str_where = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication='n' and " + Request.Form.Get("class_select").ToString() + " like '%" + str_where + "%'";
            BindGrid Bgrid = new BindGrid();
            Bgrid.Opencon(str_where);
            Bgrid.BindGrid1(Bgrid.sda);
            DataGrid1.DataSource = Bgrid.ds.Tables[0];
            DataGrid1.DataBind();
            Bgrid.con.Close();
        }
        else
        {
            str_where = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication='n'";
            BindGrid Bgrid = new BindGrid();
            Bgrid.Opencon(str_where);
            Bgrid.BindGrid1(Bgrid.sda);
            DataGrid1.DataSource = Bgrid.ds.Tables[0];
            DataGrid1.DataBind();
            Bgrid.con.Close();
        }    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        // 认证信息        Authentication Action = new Authentication(DataGrid1);           //调用Authencication类,更新所选择中的类        str_where = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication='n'";
        BindGrid Bgrid = new BindGrid();
        Bgrid.Opencon(str_where);
        Bgrid.BindGrid1(Bgrid.sda);
        DataGrid1.DataSource = Bgrid.ds.Tables[0];
        DataGrid1.DataBind();
        Bgrid.con.Close();    }
    private void ShowStats()
    {
        Label1.Text = "共" + DataGrid1.PageCount.ToString() + "页";
        Label2.Text = "第" + (DataGrid1.CurrentPageIndex + 1).ToString() + "页";    }    protected void lbt_first_Click(object sender, EventArgs e)
    {
        DataGrid1.CurrentPageIndex = 0;    }
    protected void lbt_flont_Click(object sender, EventArgs e)
    {
        if (DataGrid1.CurrentPageIndex > 0)
        {
            DataGrid1.CurrentPageIndex -= 1;
        }    }
    protected void lbt_next_Click(object sender, EventArgs e)
    {        if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
        {
            DataGrid1.CurrentPageIndex += 1;
        }
        Bgrid.BindGrid1(Bgrid.sda);
        DataGrid1.DataSource = Bgrid.ds.Tables[0];
        DataGrid1.DataBind();
    }
    protected void lbt_finally_Click(object sender, EventArgs e)
    {
        DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);
    }
}
 

解决方案 »

  1.   

    还有一个事件才能分页    protected void DataGrid1_PageIndexChanged1(object source, DataGridPageChangedEventArgs e)
        {
            this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
            this.binddate();
        }
      

  2.   

    protected void DataGrid1_PageIndexChanged1(object source, DataGridPageChangedEventArgs e)
        {
            this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
            this.binddate();
        }//////////////////// this.binddate();这一句不太明白~~~
      

  3.   

    protected void DataGrid1_PageIndexChanged1(object source, DataGridPageChangedEventArgs e)
    {
    this.DataGrid1.CurrentPageIndex = e.NewPageIndex;//设置新页数this.binddate();//重新绑定数据源
    }