foreground Code
<asp:templatefield headertext= "select" > <itemtemplate></ Itemtemplate><asp:checkbox id= "CheckBox2" runat= "Server" ></asp:checkbox></asp: Templatefield><asp:button id= "Button1" onclick= "Button1_Click" runat= "Server" text= " Select "></asp:button><asp:button id=" Button2 onclick= "button2_click" runat= "Server" text= "Delete selected" ></asp:button>
Background code
Protected void button1_ Click (object sender, eventargs e) { if (button1.text == "All selected") { foreach (gridviewrow row in gridview1.rows) { checkbox checkbox2 = (CheckBox) row. Cells[0]. FindControl ("CheckBox2"); checkbox2.checked = true; } button1.text = "all not selected" ; } else { foreach (gridviewrow row in gridview1.rows) &NBsp { checkbox checkbox2 = (CheckBox) row. Cells[0]. FindControl ("CheckBox2"); checkbox2.checked = false; } button1.text = "All selected "; } } protected void button2_click (object sender, eventargs e) { foreach (gridviewrow row in gridview1.rows) { checkbox checkbox2 = (CheckBox) row. Cells[0]. FindControl ("CheckBox2"); if (checkbox2.checked == true) { SqlConnection Conn = fun.initconn (); sqlcommand comm = new sqlcommand (); comm. Connection = conn; comm. commandtext = "Delete from comment where comment_id= '" + row. CELLS[2]. text + "' "; conn. Open (); comm. ExecuteNonQuery (); conn. Close (); } } }