How do I filter a generic list in .Net2.0?
I am using asp.net 2.0 and C#.
I have a generic list,
List<EmployeeInfo> empInfoList;
this list is loaded with the employee information. Now, I want to filter this list with the textbox value. Which is "EmploeeName".
I have to filter this list with the employeeName, and bind it to the 开发者_C百科gridview again.
I am not sure how can I do that. Please help.
Thanks in advance.
As you're using .Net2.0 you can't use LINQ, however you can use a delegate and the FindAll method:
string criteria = EmployeeName.Text.Trim().ToLower();
List<EmployeeInfo> resultList = empInfoList.FindAll(
delegate(EmployeeInfo p)
{
return p.EmployeeName.ToLower().Contains(criteria);
}
);
精彩评论