0

I have a table which has an Id and a name field. I usually bind the name to the dropdownlist but I was told that any dml should be on the Id so how can I use the name in the dropdownlist and at the same time still use the Id?

John
  • 11
  • 1
  • possible duplicate of http://stackoverflow.com/questions/2675067/binding-listbox-to-listobject – Joey Apr 20 '10 at 15:51
  • A very similar question was just answered a little while ago - [here](http://stackoverflow.com/questions/2675067/binding-listbox-to-listobject) – Ray Apr 20 '10 at 15:47

2 Answers2

2

Use DataTextField and DataValueField when binding:

ddlList.DataSource = thesource;
ddlList.DataTextField = "Name";
ddlList.DataValueField = "ID";
ddlList.DataBind()

Where ID and Name are fields in your data source.

Paddy
  • 33,309
  • 15
  • 79
  • 114
0

You can set the dropdownlist's Text field to the name and the Value field to the ID.

Aaron
  • 7,431
  • 12
  • 35
  • 37