protected void btnDel_Click(object sender, EventArgs e) { try { con.ConnectionString = ConString; con.Open(); foreach (GridViewRow row in grdvw.Rows) { //CheckBox cb = (CheckBox)row.FindControl("chkDel"); CheckBox cb = (CheckBox)grdvw.Rows[row.RowIndex].FindControl("chkDel"); if (cb.Checked) { //int id =Convert.ToInt32( grdvw.DataKeys[row.RowIndex]["Emp_no"].ToString); int Emp_no = Convert.ToInt32(grdvw.DataKeys[row.RowIndex].Values[0].ToString()); cmd = new SqlCommand("Delete from employee where Emp_no=" + Emp_no, con); cmd.ExecuteNonQuery(); con.Close(); BindData(); lblMsg.Text = "Selected Records Deleted"; } } } catch (Exception ex) { Response.Write(ex.Message); } }
int Emp_no = Convert.ToInt32(grdvw.DataKeys[row.RowIndex].Value);
int Emp_no = Convert.ToInt32(grdvw.DataKeys[row.RowIndex].Values[0].ToString());
int Emp_no = int.Parse(grdvw.CurrentCell.RowIndex.ToString());string Emp_noString = grdvw[0, currentRow].Value.ToString();Emp_noInt = int.Parse(Emp_noString );
con.ConnectionString = ConString; con.Open(); foreach (GridViewRow row in grdvw.Rows) { //CheckBox cb = (CheckBox)row.FindControl("chkDel"); CheckBox cb = (CheckBox)grdvw.Rows[row.RowIndex].FindControl("chkDel"); if (cb.Checked) { int Emp_no = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString()); cmd = new SqlCommand("Delete from employee where Emp_no='" + Emp_no + "'", con); cmd.ExecuteNonQuery(); //con.Close(); this should not come here. BindData(); lblMsg.Text = "Selected Records Deleted"; } } con.Close();
con.ConnectionString = ConString; con.Open();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)