读书人

未将对象引用设置到对象的实例 出有关

发布时间: 2012-04-25 19:32:32 作者: rapoo

未将对象引用设置到对象的实例 出问题代码如下
protected void DropDownList1_DataBinding(object sender, EventArgs e)
{
DropDownList DropDownList1 = (DropDownList)GridView1.FindControl("DropDownList1");
string sql = "select Priority from [User] ";
SqlDataAdapter da = new SqlDataAdapter(sql, DBHelper.Connection);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Priority";
DropDownList1.DataValueField = "Priority";
DropDownList1.DataBind();
}

[解决办法]
看看异常的堆栈,可以看到是哪行代码出错,

目测应该是(DropDownList)GridView1.FindControl("DropDownList1");反回null,

或者是DBHelper.Connection等于null,

读书人网 >C#

热点推荐