看看我的问题,急~~~~
这是我测试页的代码:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource2.SelectCommand = "select * From t_94 ";
SqlDataSource2.DeleteCommand = "delete from t_94 where id = @id ";
GridView3.DataSource = SqlDataSource2;
GridView3.DataBind();
Response.Write( " <script language=javascript> alert( 'load ') </script> ");
}
protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlDataSource2.DeleteParameters.Add( "id ", GridView3.DataKeys[e.RowIndex].Value.ToString());
SqlDataSource2.Delete();
GridView3.DataBind();
Response.Write( " <script language=javascript> alert( 'deleting ') </script> ");
}
}
结果发现点击GridView3上的删除,系统先执行的是pageload再执行RowDeleting,是这样的吗??? 但是我修改的一个页面上面,我写这样的代码,有时候删除了2条记录,而测试页上面没有问题
------解决方案--------------------加上IsPostBack 这样就不会出现重新绑定,因为重新绑定后值和事件就丢了
------解决方案--------------------按钮事件里删除完了再绑定一次gridview
或者if (!IsPostBack)里面写绑定代码