Hi i have no idea on how to resolve gridview events are executing twice with one hit like, rowupdating,rowcanceling and rowdeleting events please give me solution i am facing lot of problems.
i tried like,
cases:
case1)In
page_load()
{
(!page.ispostback)
}
case2). In gridview events like row_updating etc.
{
try
{
}
catch
{
}
Finally
{
e.cancel=true
}
}
case3):
executed on both browesrs are like IE and Google crome eventough i am getting same problem, with these possibilities also i am not getting solutions so please concentrate on this problem and i am sending code in below please view my code.
In webpage contains the following code:
Page_Load(object sender, System.EventArgs e)
{
if (Session["OrgCode"] == null) {
Response.Redirect("index.aspx");
}
if (!Page.IsPostBack) {
loadCourse();
loadSection();
loadClass();
}
}
gvClass_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
try {
int admno = Convert.ToInt32(gvClass.DataKeys(e.RowIndex).Values("AdmNo").ToString());
cn.ConnectionString = ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString;
cn.Open();
SqlCommand cmd = new SqlCommand("delete from AdmTable where AdmNo=" + admno, cn);
int result = cmd.ExecuteNonQuery();
cn.Close();
if (result == 1) {
BindDataGrid1();
lblresult.ForeColor = Color.Green;
lblresult.Text = "Admission Number" + admno + " details deleted successfully";
}
} catch (Exception ex) {
ClientScript.RegisterStartupScript(this.GetType, "alert", "javascript:alert('" + ex.Message + "');", true);
}
}
protected void gvClass_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
try {
gvClass.EditIndex = e.NewEditIndex;
BindDataGrid1();
} catch (Exception ex) {
ClientScript.RegisterStartupScript(this.GetType, "alert", "javascript:alert('" + ex.Message + "');", true);
}
}
please give me solution.