另外 ,我用的是c# ,在后台写的代码(.cs文件) ,请帮助我的人不要粘帖在aspx里写的东西

解决方案 »

  1.   

    what is your datasource? for paging, don't use DataReader, and also implement a PageIndexChanged event handler
      

  2.   

    的确,我用的就是 DataReader:
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DbConnSql110"]);
    conn.Open();
    SqlCommand cmd=new SqlCommand("select * from wqnews",conn);
    SqlDataReader sdr= cmd.ExecuteReader();
     DataGrid1.DataSource=sdr;
    DataGrid1.DataBind(); 
    }
    ===========================================
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
             DataGrid1.DataBind(); 
    }
    ===========================================
    to    Amilsx(一个人住) 
    我那个“上一页,下一页 ”是由 属性生成器 里的“分页”弄成的,还可以选择数字呢
      

  3.   

    don't use DataReadervoid BindData()
    {
      SqlDataAdapter da=new SqlDataAdapter ("select * from wqnews",System.Configuration.ConfigurationSettings.AppSettings["DbConnSql110"]);
      DataTable dt = new DataTable();
      da.Fill(dt);
      DataGrid1.DataSource=dt.DefaultView;
      DataGrid1.DataBind(); 
    }private void Page_Load(object sender, System.EventArgs e)

      if (!IsPostBack)
           BindData();
    }
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
             BindData(); 
    }
      

  4.   

    把你的数据绑定代码分离出来,放在一个单独的方法中,改成这样:private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack){
    BindData();
    }
    }void BindData(){
    SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DbConnSql110"]);
    SqlDataAdapter adapter=new SqlDataAdapter("select * from wqnews",conn);
    DataTable table=new DataTable();
    adapter.Fill(table);
     DataGrid1.DataSource=table
    DataGrid1.DataBind(); 
    }
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
    BindData();
    }