protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string text = "";
        Label lbl = (Label)e.Row.Cells[1].Controls[0];//或者e.row.findcontrol("id");
        text = lbl.Text;  //这句话    未将对象引用设置到对象的实例。
        text = stringEncode.HTMLEncode(text).Trim();
        if (text.Length > 6)
        {
            text.Substring(0, 5);
        }
        lbl.Text = text;
    }

解决方案 »

  1.   

    e.Row.Cells[1].Controls[0]为空,或者不是label,所以没有Text属性,就这两种情况
      

  2.   

    兄弟,就算没人答,也要客客气气的。不要爆躁,不然没人来答的。
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                在这里头写e.row.cells[1].text试试
            }
      

  3.   

    在方法RowDataBound中执行的第一次,RowType 是Header
    也就是说你在 Header 中的 e.Row.Cells[1].FindControl("Label1"); 是没有存在Label1这个控件的,这个Label应该是在 DataRow 中才有的,当NULL.Text时肯定会出现 "未将对象引用设置到对象的实例"楼上已经说了,
    加上if (e.Row.RowType == DataControlRowType.DataRow) 这句就可以了。