.net问题,在线等

来源:百度知道 编辑:UC知道 时间:2024/09/18 05:14:34
页面上有个DropDownList,这个控件里的下拉内容是从数据表里的一个字段取出来的(表名为:class 字段为:LY)
请问我怎么把class表的LY字段下的这些内容绑定到DropDownList上?

DataTable dt = new DataTable();
SqlConnection con= new SqlConnection("server=你的servername;database=数据库;uid=sa;pwd=密码;");
con.Open();
string sql="select * from class";
SqlDataAdapter da = new SqlDataAdapter(sql,con);
da.Fill(dt);
con.Close();
this.DropDownList1.DataSource=dt;
this.DropDownList1.DataTextField="LY";
this.DropDownList1.DataBind();

DropDownList.DataSource=class;
DropDownList.DisplayMember="LY";