Sep 8, 2008

Searching and Sorting in a Collections.Generic.List

We can apply searching and sorting technique in System.Collection.Generic.List .List provide full text search facility in all the columns it contains.In this example i want searching on the basis of text box value.

YourList.Where(p => p.firstName.ToLower().Contains(txtSearch.Text.ToLower()) || p.lastName.ToLower().Contains(txtSearch.Text.ToLower()) || p.status.ToLower().Contains(txtSearch.Text.ToLower()) || p.department.ToLower().Contains(txtSearch.Text.ToLower()) || p.title.ToLower().Contains(txtSearch.Text.ToLower())).ToList();
//where p is any char. Its will show all columns in intelligance

Sorting:
YourList.Sort(orderBy);
//orderBy is your sorting direction(ASC,DESC)

0 comments: