DropDownList指定的是DataTextField 和DataValueField ,然后需要DataBind();下面是一个取得数据源后绑定的例子,作下参考
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "food_name";
DropDownList1.DataValueField = "food_id";
DropDownList1.DataBind();
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "food_name";
DropDownList1.DataValueField = "food_id";
DropDownList1.DataBind();
DropDownList的数据源最好用SqlDataReader
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = 字段名//邦定DropDrowList中Item显示的文本
DropDownList1.DataValueField = 字段名//邦定DropDrowList中Item的值
DropDownList1.DataBind();
SqlDataAdapter dat=new SqlDataAdapter(cmdStr,cn);
DataSet dst=new DataSet();
dat.Fill(dst);
DropDownList1.DataSource = dst;
DropDownList1.DataTextField = 表字段名
DropDownList1.DataValueField = 表字段名
DropDownList1.DataBind();
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "food_name";
DropDownList1.DataValueField = "food_id";
DropDownList1.DataBind();
SqlConnection cn=new SqlConnection(ConnectionString);
SqlDataAdapter dat=new SqlDataAdapter(cmdStr,cn);
DataSet dst=new DataSet();
dat.Fill(dst);
DropDownList1.DataSource = dst;
DropDownList1.DataTextField = 表字段名
DropDownList1.DataValueField = 表字段名
DropDownList1.DataBind();
正解!