smile says:
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked == true)
{
select++;
}
}
if (select == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please Select Record to Delete');", true);
}
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string AdNo = GridView1.Rows[i].Cells[1].Text;
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked == true)
{
con = new SqlDbConnect();
con.SqlQuery("delete from tblSetMarks where AdmissionNo=@AdNo");
con.Cmd.Parameters.AddWithValue("@AdNo", AdNo);
con.NonQueryEx();
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Student's Marks Deteleted Successfully');", true);
this.BindSectionGrid();
}
Replace the above with the below code.
protected void btnDelete_Click(object sender, EventArgs e)
{
int select = 0;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked == true)
{
select++;
}
}
if (select == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please Select Record to Delete');", true);
}
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
Label lblAdNo = row.FindControl("lbl_AdNo") as Label;
string AdNo = lblAdNo.Text;
if (!string.IsNullOrEmpty(AdNo))
{
CheckBox Chbox = (CheckBox)row.FindControl("CheckBox1");
if (Chbox.Checked)
{
con = new SqlDbConnect();
con.SqlQuery("delete from tblSetMarks where AdmissionNo=@AdNo");
con.Cmd.Parameters.AddWithValue("@AdNo", AdNo);
con.NonQueryEx();
//GridView1.Visible = false;
}
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Student's Marks Deteleted Successfully');", true);
this.BindSectionGrid();
}