CheckBox in Grid View
Insert a CheckBox in a Grid View control-
Select the Grid View > Go to source > Put the cursor in between the Template Field > Create an Item Template tag > Put the cursor in between > Select a CheckBox from toolbox.
Delete the checked record from grid view and database-
when we checked the check box then the respective record will be deleted from grid view.
CODE-
{
string k = @"path";
cn = new SqlConnection(k);
cn.Open();
foreach(GridViewRow gr1 in GridView1.Rows)
{
CheckBox c1 = (CheckBox) gr1.FindControl("txt1");
//here we find the control, create an object of it and within double quotes we give the id of checkbox.
if(c1.checked)
{
string q = "delete from Table_name where roll = '"+gr1.Cells[1].Text +"' ";
cm = new SqlCommand(q,cn);
cm.ExecuteNonQuery();
}
}
}
Comments
Post a Comment