Indranil Sarkar

Indranil Sarkar

  • NA
  • 4
  • 1.8k

Template checkbox in Gridview is selected but returning false when running the code

Oct 26 2012 6:36 AM
I have used template CheckBox in gridview for multiple rows deletion, when I select multiple rows by selecting the CheckBox and perform the delete operation it seems to be selected CheckBox is not returning true on the code below.

protected void Button6_Click(object sender, EventArgs e)
        {

            foreach (GridViewRow row in GridView1.Rows)
            {
                LinkButton ch = new LinkButton();
                ch = (LinkButton)row.FindControl("l1");
                id = Convert.ToInt16(ch.CommandArgument);
                CheckBox chs = new CheckBox();
                chs = ((CheckBox)row.FindControl("c1"));

                if (chs.Checked == true)
                {
                    DeleteSelected(id);
                }
            }
        }

    private void DeleteSelected(short id)
    {
        var ch = from a in empd.Employees where (a.ID == id) select a;
        empd.Employees.DeleteAllOnSubmit(ch);
        empd.SubmitChanges();
        display_emp();
    }



Well now I have fixed the connection everything, please just refresh the database.Please get the web application in the below link.

<a href=http://www.ziddu.com/download/20716096/WebApplication.zip.html>http://www.ziddu.com/download/20716096/WebApplication.zip.html</a>
Please help me on why selected checkbox are not returning true in the code.


Answers (1)