Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to bind two fields to dropdownlist in c#.net

I have to bind empid and empname to dropdownlist
C#
ddlselectuser.DataTextField = "empname";
ddlselectuser.DataValueField = "empid";
ddlselectuser.DataBind();

but it is does not adding two values

how to add two values to dropdownlist

because i have to catch empid when dropdownlist empname is selected

please help me
Posted
Updated 6-Dec-11 0:53am
v2
Comments
Wendelius 6-Dec-11 6:53am    
Pre tags added
Karthik Harve 6-Dec-11 6:56am    
does the datasource for the control has two columns like "empname" and "empid"..???
Member 7932936 6-Dec-11 7:32am    
yes

There is no way to bind two column in dropdownlist... try to combine two column values at database side and bind it.

e.g. SELECT (efname + " - " + elname) as ename from employeemaster..
 
Share this answer
 
C#
DropDownList1.DataSource = ddDR;
DropDownList1.DataTextField = "DisplayValueFieldFromDB";
DropDownList1.DataValueField = "DataValueFieldFromDB";
DropDownList1.DataBind();



ddDR is DataSource
 
Share this answer
 
Comments
Member 7932936 6-Dec-11 7:34am    
it's not working
Abhi KA 6-Dec-11 8:39am    
write your datasource code

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