dimanche 2 juillet 2017

Checking or unchecking a gridview checkbox dynamically

I have two gridviews, one is on the main page and the other is modal. Both gridviews have one checkbox defined as asp:TemplateField.

What I want is: When I click one checkbox on the modal gridview, all the related checkboxes checked. The code is as follows:

    protected void Secil_CheckedChanged(object sender, EventArgs e)
    {
        int selRowIndex = ((GridViewRow)(((CheckBox)sender).Parent.Parent)).RowIndex;
        CheckBox cb = (CheckBox)GridIller.Rows[selRowIndex].FindControl("Secil");

        if (cb.Checked)
        {
            string secili = HttpUtility.HtmlDecode(GridIller.Rows[selRowIndex].Cells[1].Text);
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox cb1 = (CheckBox)row.FindControl("Sec");
                if (HttpUtility.HtmlDecode(row.Cells[7].Text) == secili)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        GridView1.EditIndex = -1;
                        cb1.Checked = true;
                    }

                }
            }
        }

When I debug the program I see that cb1.checked; statement is executing but checkbox in the gridview remains unchecked.




Aucun commentaire:

Enregistrer un commentaire