Hi all,

I am using a checkbox list which getting binded/taking datasource from LINQ query. can any body tell me how can I sort the checkbox list Alphabetically ?

I have the following code  in c.s file.


            CheckboxCatergory.DataSource = db.MST_SecondLevelExperts.Where(i => i.Expertise_id == PractiseArea);
            CheckboxCatergory.DataTextField = "Name";
            CheckboxCatergory.DataValueField = "ExpertSubType_id";

MST_SecondLevelExperts is a view in sql server 2008, When I run the view (query) I get alphabetically sorted result.

I have used Order By Name , But after binding in checkboxlist it is not sorted alphabetically… please help.

try this ;


CheckboxCatergory.DataSource = db.MST_SecondLevelExperts.OrderBy(x=> x.Name).Where(i => i.Expertise_id == PractiseArea);

Please change it as

db.MST_SecondLevelExperts.Where(i => i.Expertise_id == PractiseArea).OrderBy(c=>c.Name).ToList();

Leave a Reply