如下代码,提示错误“未将对象引用设置到对象的实例。”出错的行为“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;
}
}
”。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;
}
}
VoteView HeaderRow 还是 Cells[0]
VoteView.HeaderRow.Cells[0】和sHeadText都可能为null
判断一下先。
if (sHeadText !=null)
也可以对)&&(VoteView.HeaderRow对象判断是否为空.是不是你的数据集没有记录啊?