Click here to Skip to main content
15,742,150 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I have a DropDownList Control in my page,

i am binding both DataValueField and DataTextFiled to it.

For example: Employee details,

Data value Field =1
Data Text Field ="ABCD"

i want the text in dropdownlist will show like this


and also i want to select the Data Value Field from this dropdownlist

thats 1 in above example

How can i do this

Please help
Updated 15-Feb-11 20:23pm

Share this answer
Either create a custom object or get the textfield value as '1 - ABCD' from query itself.

For now, it looks like you are a beginner, try the Query way. When fetching the data, concatenate the ID and Text field and then use this field as the datatextfield while binding.

  ID, TextF, (ID + '-' + TextF) AS IDTEXTF

mydropdown.Datasource = myFetchedDataTable;
mydropdown.DataValueField = "ID";
mydropdown.DataTextField = "IDTEXTF";
Share this answer
kapilonkar 4-Mar-13 1:53am    
Can anyone Tell me if I do not want to pass DataTextField and DataValueField how can I bind DropDownList with datasource ?
At present I am getting bound Value as System.Data.DataRowView for all the Items.

Please Tell me If anyone knows the Solution.

Thanks in Advance.
Sandeep Mewara 4-Mar-13 2:03am    
You have to define the datatextfield and datavaluefield to map the field/value.

Further, next time, please post your questions as a new question instead of a comment to any question previously asked by someone else.
kapilonkar 4-Mar-13 3:33am    
Yes Sure,

Thanks for Information Sandeep.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900