日期:2014-05-18  浏览次数:20507 次

求助gridview的删除提示框问题
错误提示: 未将对象引用设置到对象的实例。 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  LinkButton lb = (LinkButton)e.Row.FindControl("lb") as LinkButton;
  lb.Attributes.Add("onclick", "return confirm('确定删除吗?')");
  }
  }

------解决方案--------------------
LinkButton lb = (LinkButton)e.Row.FindControl("lb");

 LinkButton lb = e.Row.FindControl("lb") as LinkButton;

------解决方案--------------------
LinkButton lb = e.Row.FindControl("lb") as LinkButton;
if(lb!=null){}

OnClientClick="return confirm('确定删除吗?')"
------解决方案--------------------
一句代码的事情,有必要搞的那么麻烦吗?
C# code
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType.ToString() == "DataRow")
        {
            ((LinkButton)e.Row.Cells[5].FindControl("LinkButton1")).Attributes.Add("onclick", "return confirm('是否删除')");
        }
    }

------解决方案--------------------
在页面的控件里加个事件
OnClientClick="return confirm('确定删除吗?')"