lundi 16 avril 2018

Find checkbox column in gridview OnCheckedChange event

I have few gridview columns with checkboxes control that has an autopostback='true' to update a db.

enter image description here

When i check one of the checkboxes the entire row gets updated which makes me frustrated.

I'm trying to find the checkbox control of the column not the whole gridview

I know that Mycheckbox.checked will always be true because it looks at the "checked values for all" however i want it only to look in the column specified

Is it possible to do something like Checbox MyCheckbox = findcontrol(MyColumn)......

protected void myCheckBox_OnCheckedChange(object sender, EventArgs e)
{

    CheckBox myCheckBox = (CheckBox)sender;
    GridViewRow row = (GridViewRow)myCheckBox.NamingContainer;
    bool status = myCheckBox.Checked;       


    string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;


    using (SqlConnection con = new SqlConnection(CS))
    {
        SqlCommand cmd = new SqlCommand("sp_tblPlanningChecked", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@PlanningID", row.Cells[1].Text);
        cmd.Parameters.AddWithValue("@ThisWeekMinus2", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus1", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeek", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekPlus1", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekPlus2", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus3", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus4", myCheckBox.Checked);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

}




Aucun commentaire:

Enregistrer un commentaire