当我单击删除按钮时,相应的行将被删除。但是gridview中的其余行变得不可见。但是当我再次单击那些链接按钮时它会正确显示。请帮我。代码在这里:
protected void LinkButton2_Click(object sender, EventArgs e)
{
try
{ SqlConnection con = obj.getcon();
con.Open();
GridView1.Visible = true;
SqlDataAdapter adapter = new SqlDataAdapter("select e.student_id,e.student_name,e.student_nric from student_details e join student_vs_testsession_details f on e.student_id=f.student_id where f.testsession_id='" + lb_testid.Text + "' ", con);
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex);
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id =Convert.ToString (GridView1.DataKeys[e.RowIndex].Value);
SqlConnection con = obj.getcon();
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM student_vs_testsession_details WHERE student_id='" + id + "'", con);
// con1.Open();
int temp = cmd.ExecuteNonQuery();
if (temp != 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert(' record deleted succesfully')", true);
}
con.Close();
GridView1.Visible = true;
GridView1.DataBind();
}