日期:2014-05-18  浏览次数:20650 次

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