Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
}
Could someone please assist me why CheckBox is not returning a true value in calling function.

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

http://www.ziddu.com/download/20716096/WebApplication.zip.html Please help me with why selected checkbox is not returning true in the code.
Posted
Updated 26-Oct-12 0:30am
v4
Comments
Indranils 26-Oct-12 6:29am    
Please someone could help me on why this checkbox is not working (returning false) in running of code when it's selected.

Hi

I have seen your code you have small issue in your code. i.e. your grid view is populated on every post back modify your page load event as follows put the following code into the load event 

C#
if (IsPostBack == false)
            {
                empd = new Employee_DetailsDataContext();
                empd.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DemosConnectionString1"].ConnectionString;
                display_emp();
            }
 
Share this answer
 
Comments
Indranils 26-Oct-12 7:16am    
Thank you so much it's worked for me.

But now I am facing one more problem why retrieval of a querry (var ch = from a in empd.Employees where (a.ID == Convert.ToInt16(id)) select a) giving an exception Object reference not set to an instance of an object.

Could you please resolve this as well for me?
Hi
I haven't check the complete functionality of the page please use the following code into the page load

C#
empd = new Employee_DetailsDataContext();
empd.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DemosConnectionString1"].ConnectionString;
  if (IsPostBack == false)
    {
        display_emp();
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900