c# - comparing two List<> -
i have gridview control checkbox on it
when hit on save button able find checkbox have been checked , able far problem is:
let if user tries uncheck checkedbox how track changes , save db has been checked. anyhelp?.. in regards have created 2 list comparision... hope make sense here.
i want compare 2 list , if changes 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 list list<employee> selectedemployee = new list<employee>(); selectedemployee = myselectedemployee //loads list //employee object looks this: id name
here got stuck , here doing...
foreach (employee item in myselectedemployee ) { bool _flag = false; _flag = employeeservice.saveemployee(item.id, item.name); }
you want this:
var diff = selectedemployee.except(listfromdb, (a,b)=>a.id==b.id); foreach (employee e in diff) { employeeservice.saveemployee(e.id, e.name); }
but you're awful short on particulars. defines change? how match items in list: id? can more exact requirements?
Comments
Post a Comment