Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I clear a child gridview when using checkboxes

Status
Not open for further replies.

citizenzen

Programmer
Jun 28, 2007
102
US
I have a major problem. i am implementing checkboxes in my gridviews in place of the select link. the checkboxes work fine, but i am unable to clear the data from my child gridviews. the child gridview refreshes (seems to) on pageIndexChanging. I can't figure out how to rebind when the user checks a record that is within the same page block. do i need to implement selectedIndexChanged?? I don't see how to clear the detailsgrid and show data when the checkbox is selected.

here's what i am doing so far.


Code:
    protected void Page_Load(object sender, EventArgs e)
    {  if (!IsPostBack)
        {taskListGrid.DataBind();
            reqdetsgrid.DataBind();}

  private void BindtaskListGrid() //initial grid
    {        
//connection info here.......
   reqDumpDS.Connection.Open();
            reqDumpDS.CommandType = CommandType.StoredProcedure;
            reqDumpDS.Parameters.Add("@status", SqlDbType.Int, 4);
            reqDumpDS.Parameters["@status"].Value = 1;
            reqDumpDS.ExecuteNonQuery();
            reqDumpDS.Connection.Close();
            taskListGrid.DataBind();          
  taskListGrid.Dispose();
    }

 protected void taskListGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {  taskListGrid.PageIndex = e.NewPageIndex;
            reqdetsgrid.DataBind();   }

    protected void selectReqchk_CheckedChanged(object sender, EventArgs e)
    {
       RemoveCheckBoxes();                 
           CheckBox checkbox = (CheckBox)sender;
           checkbox.Checked = true;
           GridViewRow row = (GridViewRow)checkbox.NamingContainer;
            BindtaskListDetails(); 
}
    private void RemoveCheckBoxes()
    {
        foreach (GridViewRow row in taskListGrid.Rows)
        {  CheckBox ch = (CheckBox)row.FindControl("selectReqchk");
            ch.Checked = false;     }    }
 private void BindtaskListDetails()
    {   //uses datatable to bind to gridview
                int initialReq = Convert.ToInt32(taskListGrid.DataKeys[1].Value);
                detDumpSQL.Connection.Open();
                detDumpSQL.CommandType = CommandType.StoredProcedure;
                detDumpSQL.Parameters.Add("@req", SqlDbType.Int);
                detDumpSQL.Parameters["@req"].Value = initialReq;

                //new, declare datatable
                DataTable appdetdt = new DataTable();
                SqlDataAdapter appdetadap = new SqlDataAdapter(detDumpSQL);
                appdetadap.Fill(appdetdt);
                reqdetsgrid.DataSource = appdetdt.DefaultView; // appdetdt.DefaultView;
                reqdetsgrid.AutoGenerateColumns = false;
//add columns-- temporarially removed for example
reqdetsgrid.Columns.Add(appd1);

                reqdetsgrid.DataBind();
                detDumpSQL.Connection.Close();
                appdetdt.Rows.Clear();
                reqdetsgrid.Dispose();
}
 
I'm not sure what it is you need for sure... but I'm thinking that maybe you need to set the AutoPostBack property of the checkboxes to True so that your events fire on the server side.

Senior Software Developer
 
ok. Is your code that binds the data to the DetailGrid executed by the Checkbox.CheckedChanged Event?

Also, are your checkboxes static, or is there one on each row of another DataGrid?

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top