Pranav
Pranav

Reputation: 8871

Population of ComboBox with DisplayMember and ValueMember

I am trying to populate Combox like this :

        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"];

But all item are showing as "System.Data.DataRowView" in Combobox. why it is like that? Thanks in Advance.

Upvotes: 0

Views: 15032

Answers (2)

Alvin
Alvin

Reputation: 995

try this:

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();

Upvotes: 2

Karthik
Karthik

Reputation: 2399

try  comboProject.DataSource = ds.Tables["FillDropDown"].DefaultView;

Upvotes: 1

Related Questions