SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
con.Open();
string cmdtext = "select lname from lanmu";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds, " lname");
this.DropDownList1.DataSource = ds.Tables["lname"].DefaultView;
DropDownList1.DataValueField = "lname";
DropDownList2.DataTextField = "lname";
DropDownList1.DataBind();
con.Close();但是总是提示未将对象引用设置到对象的实例。 这哪里错了?
con.Open();
string cmdtext = "select lname from lanmu";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds, " lname");
this.DropDownList1.DataSource = ds.Tables["lname"].DefaultView;
DropDownList1.DataValueField = "lname";
DropDownList2.DataTextField = "lname";
DropDownList1.DataBind();
con.Close();但是总是提示未将对象引用设置到对象的实例。 这哪里错了?
string strSQL = "select * from class where parent_ptr="+strId ;
db d = new db();
DataTable dt = d.getDT(strSQL); this.ddl2.DataSource = dt;
this.ddl2.DataTextField = "classCName";
this.ddl2.DataValueField = "id";
this.ddl2.DataBind();
DropDownList1.DataValueField = "lname";
DropDownList2.DataTextField = "lname"; // 怎么是2了又
DropDownList1.DataBind();