如下代码,提示错误“未将对象引用设置到对象的实例。”出错的行为“VoteView.HeaderRow.Cells[0].Text = sHeadText;
”。VoteView是控件GridView。这里怎么会出错的呢。帮帮忙哈,急!!!
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class Controls_VoteCt : System.Web.UI.UserControl
{
    private static string sHeadText = "";
    protected void Page_Load(object sender, EventArgs e)
    {   ///显示当前投票主题的信息
        BindSubjectData(GetCurrentTopic());
       VoteView.HeaderRow.Cells[0].Text = sHeadText;
        
    }
}

解决方案 »

  1.   

    这里有很多对象可能为null,你调试一下,看看是
    VoteView HeaderRow 还是 Cells[0]
      

  2.   

    如果为NULL这里改如何处理呢。
      

  3.   

    看看哪个为null了,再看看绑定的数据,如果绑定的数据没有行,可能会发生这样的情况...
      

  4.   

    两种可能
    VoteView.HeaderRow.Cells[0】和sHeadText都可能为null
    判断一下先。
    if (sHeadText !=null)
    也可以对)&&(VoteView.HeaderRow对象判断是否为空.是不是你的数据集没有记录啊?