比较两个List&LT;&GT; [英] comparing two List<>
问题描述
我有上有一个复选框GridView控件
当我打的保存按钮我能找到已检查的复选框,我能够做到这一点到目前为止好,但问题是:
如果让用户尝试取消选中checkedbox所以如何将我跟踪更改,并保存到已检查了分贝说。 anyhelp?..所以在这方面我已经创建了两个名单对比...希望我意义在这里。
我想比较两个列表,如果任何更改,然后保存别的....做些什么...
&LT; ASP:的TemplateField的HeaderText =选择&GT; &LT;&ItemTemplate中GT;
&LT; ASP:复选框ID =chkSelected=服务器选中=假&GT;&LT; / ASP:复选框&GT;
&LT; / ItemTemplate中&GT; &LT; / ASP:的TemplateField&GT;
清单&LT;员工&GT; listFromDB =新的List&LT;员工&GT;();
listFromDB = EmployeeListFromDB; //加载列表清单&LT;员工&GT; selectedEmployee =新的List&LT;员工&GT;();
selectedEmployee = MySelectedEmployee //加载列表// Employee对象如下:
ID
名称
这里是我被困,这里是我在做什么...
的foreach(在MySelectedEmployee员工项)
{
布尔_flag = FALSE;
_flag = EmployeeService.SaveEmployee(item.Id,item.Name);
}
这里是你会怎么做:
列表&LT;员工&GT;找到= EmployeeListFromDB.FindAll(A =&GT;!selectedEmployee.Exists(B = GT; a.Id == b.Id));
完蛋了...
i have gridview control with a checkbox on it
When i hit on save button i able to find the checkbox which have been checked and i able to do it so far so good but the problem is:
let say if the user tries to uncheck the checkedbox so how would i track the changes and save it into the db that has been checked. anyhelp?.. so in that regards i have created two list for comparision... hope i make sense here.
i want to compare the two list and if any changes then save else ....do something...
<asp:TemplateField HeaderText="Select"> <ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" Checked="false"></asp:CheckBox>
</ItemTemplate> </asp:TemplateField>
List<Employee> listFromDB = new List<Employee>();
listFromDB = EmployeeListFromDB ; //loads the list
List<Employee> selectedEmployee = new List<Employee>();
selectedEmployee = MySelectedEmployee //loads the list
//Employee object looks like this:
id
name
here is what i got stuck and here is what i am doing...
foreach (Employee item in MySelectedEmployee )
{
bool _flag = false;
_flag = EmployeeService.SaveEmployee(item.Id, item.Name);
}
here is how you would do:
List<Employee> found = EmployeeListFromDB.FindAll(a=>!selectedEmployee.Exists(b=>a.Id == b.Id));
thats it...
这篇关于比较两个List&LT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!