Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to bind more then one datatextfield to dropdownlist in asp.net
Posted
Comments
KM Perumal 3-May-13 3:53am    
Retrieve data and add manually into dropdownlist ..
Pr@senJeeT 3-May-13 4:00am    
how to add manually...
can u explain ?
Pr@senJeeT 3-May-13 4:01am    
I retrieve all data but only one column allow me to bind with datatextfield.
KM Perumal 3-May-13 4:13am    
Dont bind column..bind one by one item into dropdownlist ...or show ur code
Thanks7872 3-May-13 4:01am    
can you show the code you have tried till now?

C#
public class Data
    {
        public int Id { get; set; }
        public string Col1 { get; set; }
        public string Col2 { get; set; }
        public string Col3 { get; set; }

    }

var data = List<data>();

var dropdownData = data.Select(x=>new {Id = x.Id, Value = x.Col1+ "|" + x.Col2 + "|" + x.Col3}).ToList();

DropdownList.DataSource = dropdownData;
 DropdownList.DataTextField = "Value";
 DropdownList.DataValueField = "Id";
DropdownList.DataBind();
</data>


You can create generic list as displayed above and bind it with dropdown.
You will get 3 values binded with Dropdown concatened with "|".
 
Share this answer
 
You can merge two column in your sql query like if you want to show the first_name and last_name to your dropdown you can use following query...

select first_name + ' ' + last_name as full_name from tbl_name

now you can bind full_nameto your dropdown.Hope this will help in your problem...
 
Share this answer
 
thanks guys i got solution....


IList<pm_clientinformation> objPM_ClientInformation = new List<pm_clientinformation>();

//get information in objPM_ClientInformation

foreach (PM_ClientInformation f in objPM_ClientInformation)
{
string text = string.Format("{0}{1}",
f.PM_cliFirstName.PadRight(10,'\u00A0'),
f.PM_cliLastName.PadRight(10,'\u00A0'));
ddlClientName.Items.Add(new ListItem (text ,f.PM_cliId.ToString()));
}
 
Share this answer
 

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