日期:2014-05-19  浏览次数:20431 次

GridView删除时,判断的问题!
GridView定义了OnRowDeleting   和   OnRowDeleted事件,我想在OnRowDeleting中判断是否能够删除。
现在问题是如果判断不能删除,怎样才能不让OnRowDeleted事件发生,也就是不删除数据并且给出一个不能删除的提示?

------解决方案--------------------
OnClientClick= "return confirm( '您确定要删除? '); "
------解决方案--------------------
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//假设这里写判断不能删除的逻辑
if (GridView1.Rows.Count <= 1)
{
e.Cancel = true;
Response.Write( " <Script language=javascript> alert( '不能删除 '); </script> ");
}
}
------解决方案--------------------
一楼做法最为简单,在linkbutton添加confirm()
------解决方案--------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{

((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add( "onclick ", "javascript:return confirm( '你确认要删除:\ " " + e.Row.Cells[1].Text + "\ "吗? ') ");

}
------解决方案--------------------
在onpage_load事件里面对对应按钮
添加:
if(!this.IsPostBack)
{
this.Button1.Attributes.Add( "onclick ", "javascript:return confirm( '确定删除吗? '); ");
}

------解决方案--------------------
晕,没看清楚楼主的问题。。
------解决方案--------------------
二楼hccl(jackie)的方法看似可行
------解决方案--------------------
回滚