开发者

How do I filter a generic list in .Net2.0?

开发者 https://www.devze.com 2023-01-05 23:00 出处:网络
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 va

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);
   }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消