0

I have a DropDownList which is having few list items. Every time I select any item, based on it I am binding a gridview, hence resulting gridview depends on my selection. Some results are exceeding the pagesize hence I need to navigate on 2nd page in GridView, however the GridView is disappeating when I am selecting 2nd page.

 protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
 {
    string constr = ConfigurationSettings.AppSettings["ConnectionInfo"];
    SqlConnection con = new SqlConnection(constr);

    con.Open();
    string str = string.Empty;
    str = "SELECT * FROM Table1";

    SqlDataAdapter adp = new SqlDataAdapter(str, con);

    DataSet ds = new DataSet();
    adp.Fill(ds, "myds");

    BusinessKPIGrid.DataSource = ds;
    BusinessKPIGrid.DataBind();
}

 protected void OnGridViewPaging(object sender, GridViewPageEventArgs e)
 {
    //I know I need to bind the gridview here, but how ?
    BusinessKPIGrid.PageIndex = e.NewPageIndex;
    BusinessKPIGrid.DataBind();
 }

I don't know how to bind the gridview in paging event, since I do not have any separate binding function.

4

3 回答 3

1

there is a separate function for page event for grid view..create separate method for binding grid & call that method on pageindexchange event..

protected void BusinessKPIGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    BusinessKPIGrid.PageIndex = e.NewPageIndex; 
     bindyourgrid();
}
于 2012-07-30T07:07:09.307 回答
1

try this

protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
    string constr = ConfigurationSettings.AppSettings["ConnectionInfo"];
    SqlConnection con = new SqlConnection(constr);

    con.Open();
    string str = string.Empty;
    str = "SELECT * FROM Table1";

    SqlDataAdapter adp = new SqlDataAdapter(str, con);

    DataSet ds = new DataSet();
    adp.Fill(ds, "myds");
    ViewState["ds"]=ds;
    BusinessKPIGrid.DataSource = ds;
    BusinessKPIGrid.DataBind();

}

  protected void OnGridViewPaging(object sender, GridViewPageEventArgs e)
    {
        //I know I need to bind the gridview here, but how ?
        BusinessKPIGrid.PageIndex = e.NewPageIndex;
         BusinessKPIGrid.DataSource = (DataSet)ViewState["ds"];
        BusinessKPIGrid.DataBind();
    }
于 2012-07-30T07:10:39.193 回答
0

From DDL_SelectedIndexChanged if you are searching some thing then use 'PageIndexChanging' and set the page size for it

protected void gvworker_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvworker.PageIndex = e.NewPageIndex;
        //result got from ddl list i.e bind your data set
    }
于 2012-07-30T07:10:48.477 回答