Click here to Skip to main content
11,805,604 members (55,425 online)
Rate this: bad
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 19:57pm
Edited 15-Feb-11 20: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 at 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 at 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 at 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
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.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