我正试图像这样填充Combox:
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT id,name FROM table1", con);
da.Fill(ds, "FillDropDown");
comboProject.DisplayMember = "FillDropDown.name";
comboProject.ValueMember = "FillDropDown.id";
comboProject.DataSource = ds.Tables["FillDropDown"];
但所有项目在Combobox中显示为“System.Data.DataRowView”。为什么会那样? 在此先感谢。
答案 0 :(得分:2)
试试这个:
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT id,name FROM table1", con);
da.Fill(ds, "FillDropDown");
comboProject.DisplayMember = "name";
comboProject.ValueMember = "id";
comboProject.DataSource = ds.Tables["FillDropDown"];
comboProject.DataBind();
答案 1 :(得分:1)
try comboProject.DataSource = ds.Tables["FillDropDown"].DefaultView;