protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lbDeletes = (LinkButton)e.Row.Cells[0].FindControl("LinkButton2");
        if (lbDeletes.Text.Equals("删除"))
        {
            lbDeletes.Attributes.Add("onclick", "javascript:return confirm('确认删除当前项吗?')");
        }
老是提示未将对象引用设置到对象的实例!
编辑和删除都是在第0列

解决方案 »

  1.   

    这里你要先判断一下e.Row.RowType因为它是从表头开始算的,表头不包含你的控件,一定要从RowType == DataRow 这种开始,所以要先判断。大致是这样的。具体你VS里点开看看。
      

  2.   

    你忘了加那个if:如下:
        /// <summary>
        /// 启动网页时的一些操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvDengji_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && this.gvDengji.EditIndex != e.Row.RowIndex)
            {
                LinkButton linkbtnDele = (LinkButton)e.Row.Cells[5].FindControl("lkbtnDel");
                linkbtnDele.Attributes.Add("onclick", "return confirm('确认删除吗?')");
            }
        }
      

  3.   

       if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[10].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + ((LinkButton)e.Row.Cells[3].FindControl("LinkButton")).Text + "\"吗?')");
                }
      

  4.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        {          if (e.Row.RowType == DataControlRowType.DataRow)
            {
               LinkButton lbDeletes = (LinkButton)e.Row.FindControl("LinkButton2"); 
                    
            if (lbDeletes.Text.Equals("删除")) 
            { 
                lbDeletes.Attributes.Add("onclick", "javascript:return confirm('确认删除当前项吗?')"); 
            } 
    }
      

  5.   

    问题已解决,谢谢各位,我忘记设置DataKeys了