ASP.NETGridView的RowDeleting事件string sql deletefrom food where foodName + GridView1.DataKey
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) 这个了没有?