Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By using following code I fill all the combo-box. But the items are not ia a order.How I can I set all the items in acending order.

var customer = new Customer();
                customer.FirstName = "--Select Customer--";
                customerList.Insert(0, customer);

                var customerddl = customerList.Select(custo => new Customer
                {
                    CustomerCode = custo.CustomerCode,
                    FirstName =  custo.FirstName + " " + custo.LastName
                }).ToList();

                ddlCustomers.DataSource = customerddl;
                ddlCustomers.DataTextField = "FirstName";
                ddlCustomers.DataValueField = "CustomerCode";
                ddlCustomers.DataBind();
Posted
Updated 23-Nov-13 17:39pm
v2

Try this

ddlCustomers.DataSource = customerddl.orderby(k=> k.firstname).tolist();
 
Share this answer
 
Comments
Karthik_Mahalingam 24-Nov-13 0:33am    
Take care of syntax
sachi Dash 24-Nov-13 0:56am    
Thanks a lot Brother. Now it is working !!! :D
Karthik_Mahalingam 24-Nov-13 1:00am    
Always welcome
happy coding :)
I guess you populate data using a query.
Sort the data in this query.

If you want to sort on client side, then sort the returned collection using LINQ.
 
Share this answer
 
Comments
sachi Dash 24-Nov-13 0:59am    
Yes, it is working now. I used LINQ.
try this

DataTable Dt = new DataTable();//where all data is saved to show in combobox
Dt.Columns.Add("Id");
Dt.Columns.Add("Name");
Dt.Rows.Add("0","Stephan");
Dt.Rows.Add("1","Antony");
Dt.Rows.Add("2","Mike");

Dt.DefaultView.Sort = "Name ASC";//This will turn your record in ascending order

combobox1.DataSource = Dt;
combobox1.DisplayMember="Name";
combobox1.ValueMember="Id";
 
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