日期:2014-05-17  浏览次数:20489 次

ASP.NETGridView的RowDeleting事件

        string sql = "delete  from food where foodName='" + GridView1.DataKeys[e.RowIndex].Value.ToString() +"'";
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlCommand cmd = new SqlCommand(sql, con);
        int i = cmd.ExecuteNonQuery();
        if (i>0)
        {
            Response.Write("<script>alert('删除成功')</script>");
        }
        else
        {
            Response.Write("<script>alert('删除失败')</script>");
        }
        con.Close();
        Page_Load(sender,e);

这是GridView的删除按钮触发的RowDeleting事件代码,为什么每次我删除一条数据,执行了RowDeleting事件,我刷新网页他又执行一次RowDeleting事件,我继续刷新他就继续执行RowDeleting事件。。
这是什么情况?
------最佳解决方案--------------------
page_load里面加
if (!IsPostBack)
这个了没有?

然后再加上RowDeleting 事件
 //模拟网络拥塞5秒钟 
      System.Threading.Thread.Sleep(5000);

------其他解决方案--------------------
删除之后重新绑定 BindData();方法.. 这个方法写在page_load 里面(!IsPostBack){BindData();}...我想这样可能够清楚了吧!!!!
------其他解决方案--------------------
把Page_Load(sender,e);改成Response.Redirect("你的页面地址");试试
------其他解决方案--------------------
其实你删除后重新执行绑定一次也行啊
------其他解决方案--------------------
Page_Load( sender,  e)的问题吧
------其他解决方案--------------------
引用:
Page_Load( sender,  e)的问题吧

Page_Load里面只是一个从数据库绑定数据到gridView中来而已,刷新再次执行 RowDeleting和和这个没有关系
------其他解决方案--------------------
防刷新提交???
------其他解决方案--------------------
引用:
page_load里面加
if (!IsPostBack)
这个了没有?

然后再加上RowDeleting 事件
 //模拟网络拥塞5秒钟 
      System.Threading.Thread.Sleep(5000);

就是ispostback的问题,感谢
------其他解决方案--------------------
引用:
删除之后重新绑定 BindData();方法.. 这个方法写在page_load 里面(!IsPostBack){BindData();}...我想这样可能够清楚了吧!!!!

就是ispostback的问题,感谢