satya swaroop

satya swaroop

  • NA
  • 1
  • 729

Deleting Multiple rows in a GridView

May 14 2016 8:08 AM
protected void Button1_Click(object sender, EventArgs e)<br /> {<br /> foreach (GridViewRow grow in GridView1.Rows)<br /> {<br /> CheckBox chk = (CheckBox)grow.FindControl("chk1");<br /> if (chk.Checked)<br /> {<br /> int empid =Convert.ToInt32(grow.Cells[1].Text);<br /> deleterecord(empid);<br /> }<br /> }<br /> Bind();<br /> }<br /> protected static void deleterecord(int empid)<br /> {<br /> SqlConnection con = new SqlConnection("Data Source=desktop-tvrrh2v;Initial Catalog=FROMSQL;Integrated Security=True");<br /> SqlCommand cmd = new SqlCommand("delete from grrid where id=@id", con);<br /> cmd.Parameters.AddWithValue("@id",empid);<br /> con.Open();<br /> cmd.ExecuteNonQuery();<br /> con.Close();<br /> }<div></div><div> }</div>

Attachment: WebApplication18.rar

Answers (2)