C#如何将数据绑定到comboBox上 如果是ASP.NET,将数据绑定到DropDownList上,可以用SqlDataReader这样绑定: SqlCommand mymand = new SqlCommand(txt, Con); SqlDataReader dr = mymand.ExecuteReader(); this. aBase.DataSource = dr; this. aBase.DataTextField = "name"; this. aBase.DataBind(); 如果是C#,没有DropDownList控件,可以用comboBox,将属性DropDownStyle设置成DropDownList,然后: SqlDataAdapter Adapter = new SqlDataAdapter(txt, Con); DataSet da = new DataSet(); Adapter.Fill(da); comboBox3.DataSource = da.Tables[0]; this.comboBox3.DisplayMember = "mingzi"; 可见,2 个控件用了不同的方法,一个是单程读取,加一个是数据适配器。
|