Click here to Skip to main content
11,928,352 members (46,256 online)
Rate this:
Please Sign up or sign in to vote.
See more: C ASP.NET
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
Posted 15-Feb-11 20:57pm
Edited 15-Feb-11 21:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 16 Feb 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100