views:

27

answers:

2

Hi there, I am working on a project for my college where I need to bind data from database into the combobox. I need to store the roll no / enrollment no in the "value" field of combobox and name of the student in the "text" property of the combobox. How can I do that?>???

Please reply ASAP....

+1  A: 

The two complex-bound controls you've most likely encountered are the ComboBox and the Listbox. To complex-bind one of these controls, you need to set the DataSource (where values originate), the DisplayMember (the name of the column of data that supplies the visible list items), and the ValueMember (the name of the column of data that supplies the possible control values).

combobox.DataSource = dataTable
combobox.ValueMember = "id"
combobox.DisplayMember = "name"
jimplode
if i have more than 1 records, then how can i make it out???? please suggest...
sohil vohra
I do not understand what you mean??
jimplode
+2  A: 

You will need to set the DataSource of the combobox to your datasource. Then the ValueMember for the Roll No and the DisplayMember for the name of the student.

e.g

cboStudents.DataSource = dataSet1.Tables["Students"];
cboStudents.ValueMember = "RollNumber";
cboStudents.DisplayMember = "StudentName";
Barry