October 12, 2007

Selecting Checkboxes inside the GridView Control:

How to select the checkboxes inside the Gridviewcontrol

After seraching many forums and websites i have developed my project by using this code.
Now in the button click event write this code which i have attached in blog as image:

// StringBuilder object

StringBuilder str = new StringBuilder();

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView1.Rows.Count; i++)


GridViewRow row = GridView1.Rows[i];

bool isChecked = ((CheckBox) row.FindControl("chkBox")).Checked;

if (isChecked)


// Column 2 is the name column




// prints out the result


Note:1.If u want to have StringBuilder then u have to include the namespace Using.System.Text
2.If u want to delete the datas after getting the Id then u should rewrite the code as
so that u will get the output.For ex:1,2,(inorder to delete from database)
other wise if u use
u will get the output as 12.