在新查询中对datagrid bind时把currentpageindex置为0

解决方案 »

  1.   

    比如
    this.DataGrid1.CurrentPageIndex = 0;
    this.DataGrid1.DataBind();
      

  2.   

    对呀,当然是新查询以后就设置currentpageindex置为0。
    假设原来是2页,新的查询只有一页,可你当前的currentpageindex如果还是1当然就错了,新的查询后显示第一页是完全正常的。
      

  3.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=B12283DE-DB20-4322-ACCC-12724442808A
    http://dotnet.aspx.cc/Exam/DataGridPaging/DataGridPaging.aspx
      

  4.   

    public class manage : System.Web.UI.Page
    {
     int startIndex;
     .....
    private void Page_Load(object sender, System.EventArgs e)
    {
     if (!IsPostBack)
     {
      startIndex=0;
      UpdateView();
      }
    }
    private void UpdateView()
    {
     string strCmd=".....";
     SqlConnection conn = new SqlConnection(strConn);
     SqlDataAdapter da = new SqlDataAdapter(strCmd, conn);
     DataSet ds = new DataSet();
     da.Fill(ds, "MyTable");
     DataGrid2.DataSource = ds.Tables["MyTable"].DefaultView;
     DataGrid2.DataBind();
    }
    private void DataGrid2_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
     startIndex=e.NewPageIndex*DataGrid2.PageSize;
     DataGrid2.CurrentPageIndex = e.NewPageIndex;
     UpdateView();
    }
      

  5.   

    重新查询时:要设CurrentPageIndex = 0