Hello All,

Can any one tell me how we bind data to a ComboBox from a dataset?

Thanks for your precious help

For binding a ComboBox we have to set its display as well as value member. :)

comboBox1.DataSource=null;
//Your Code for connecting to database and retrieving data in dataset1
//You have two columns in dataSet1.Tables[0] ,, "id", "name"

comboBox1.DataSource=dataSet1.Tables[0];
comboBox1.DisplayMember="name";
comboBox1.ValueMember="id";

//Rest of the code

Thanks for your reply... Saikalyankumar The link you provided is not opening... abelLazm Thanks for your help, how to add items in comboBox after binding?

.....how to add items in comboBox after binding?

dear bahed after adding these lines you data will automatically populate in combobox there is no need to add any thing like combobox.items.add();

U, can loop through each row in the Table of the Dataset and by using the combobox.items.add, u can add the items. an ex: code is here

for (int i = 0; i < dt.Rows.Count - 1; i++)
                {
                    DataRow dr = dt.Rows[i];
                    drpllist_ServerName1.Items.Add(dr["Name"].ToString());
                }

Thanks abellazm your post really worked for me...Saikalyankumar your provided link is also very useful thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.