Binding in an ASP.NET DropDownList

If you need to bind two seperate database columns bound with the Value and Text properties of a DropDownList control, it can be done using the DataValueField and DataTextField properties of DropDownList.

I have a DataTable with two columns called - Name and IdCode. I wanted to display Name as the text of a DropDownList items but IdCode as value so it can be use for other purposes.

This is how you do it.

MyList.DataSource = ds.Tables(0)
MyList.DataValueField =
"IdCode"
MyList.DataTextField = "Name"

Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.