Click here to Skip to main content
14,299,406 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Rate this:
Please Sign up or sign in to vote.

Solution 2

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";
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100