首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

未将对象引用设置到对象的实例 出有关问题代码如下

2012-04-25 
未将对象引用设置到对象的实例 出问题代码如下protected void DropDownList1_DataBinding(object sender,

未将对象引用设置到对象的实例 出问题代码如下
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,

热点排行