string userno = (this.GridView1.Rows[number].Cells[1].FindControl("lblUserNo") as Label).Text;//用户名
//未将对象引用设置到对象的实例。
各位大哥拜托~

解决方案 »

  1.   

    试试在rows 里面找
    名称对不
      

  2.   

    是在我点gridview更新按钮时获取控件的代码哦。
      

  3.   

    看看Rows有没有价值?

    看看Cells有没有值?
    应该是这两个查不到值照成的。
      

  4.   

    你判断了
     if (e.Row.RowType == DataControlRowType.DataRow)
    {}
    没?
      

  5.   

    this.GridView1.Rows[number].Cells[1].FindControl("lblUserNo") as Label
    监视为null
      

  6.   


    rows于cells都没有异常,后面获取控件才有异常。
      

  7.   

    首先确认你的按钮commandname='Update'
    你直接写到 grid 的 rowupdating 事件里,里面有一个E的参数,有行号
    string userno = (this.GridView1.Rows[行号].FindControl("lblUserNo") as Label).Text;//用户名Cells[1]. 这个可以拿了
      

  8.   


    有写commandname='Update'哦。
    我的number变量是获取的e.RowIndex。
    有试过去掉cells[1],但都没有效果。
      

  9.   

    你判断了
     if (e.Row.RowType == DataControlRowType.DataRow)
    {}
    没?
      

  10.   

    应该在GridView_RowCommand事件里面写喔
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       if (e.CommandName == "btnUpdate")
       {}
    }
      

  11.   

    你用两种方法试试1。把.Rows[number]变成.Rows[n].  n自己填2。你确定是Label???
      

  12.   

    没有哦。我的代码是这样的哦
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    我把这行代码拷过去说e没有Row定义,缺少using。
      

  13.   


    恩恩,是lable哦。好的,我试试!
      

  14.   

    更新某个字段应该是TextBox!!当然取某个不更新的字段也是可以的!!以下取更新的字段,
    在GridView1的RowUpdated中取值!!
        protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            string userno = (this.GridView1.Rows[number].Cells[1].FindControl("TextBox1") as TextBox).Text;
        }
      

  15.   


    这个错误是发生的原因:FindControl()的时候未查找到控件。
    自己好好检查一下Rows[number].Cells[1]是不是写错了,加断点调试,watch一下
      

  16.   

    我把number自己赋值=1就可以获取到。
    估计是e.RowIndex的值出错,但是我调试的时候
    int number = e.RowIndex;
    int id = Convert.ToInt32(GridView1.DataKeys[number].Value);//编号//这一行代码是可以正常运行的。
    string userno = (this.GridView1.Rows[number].Cells[1].FindControl("lblUserNo") as Label).Text;//用户名//这一行代码就出异常