SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\rAvIrAj\Downloads\Ravi\Ravi\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Grid_Bind(); } } public void Grid_Bind() { SqlCommand cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); ; DataTable dt = new DataTable(); try { cn.Open(); cmd.CommandText = "Select * from Student_Master"; cmd.Connection = cn; cmd.CommandType = CommandType.Text; da.SelectCommand = cmd; da.Fill(dt); gv1.DataSource = dt; gv1.DataBind(); cn.Close(); } catch (Exception ex) { Response.Write(ex.Message); } } protected void chk1_CheckedChanged1(object sender, EventArgs e) { try { if (((CheckBox)gv1.HeaderRow.FindControl("chk1")).Checked==true) { foreach (GridViewRow row in gv1.Rows) { ((CheckBox)row.FindControl("chk2")).Checked = true; } } else { foreach (GridViewRow row in gv1.Rows) { ((CheckBox)row.FindControl("chk2")).Checked = false; } } } catch (Exception ex) { Response.Write(ex.Message); } } protected void btn_Click(object sender, EventArgs e) { foreach (GridViewRow row in gv1.Rows) { if (((CheckBox)row.FindControl("chk2")).Checked == true) { int id = SqlCommand cmd = new SqlCommand("delete from Student_Master where id="+id,cn); Grid_Bind(); ll.Text = "successful"; } } }
//num is the index of the id column ex. gv1.Rows(i).Cells(1).Text string id = gv1.Rows(i).Cells(num).Text
int.parse(gv1.Rows(index).Cells(num).Text.ToString()); index is int type have column no index.like id,name,s_name than asign index is 0 <pre></pre>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)