DataTable mdt = dt.AsEnumerable().GroupBy(r = >new {
Col1 = r.Field < string > ("Parent Part Number"),
Col2 = r.Field < string > ("Child#1 Part Number")
}).Select(g = >g.OrderBy(r = >r.Field < string > ("Parent Part Number")).First()).CopyToDataTable();
foreach(var data in mdt.AsEnumerable()) {
Response.Write("value is " + data.Field < string > ("Parent Part Number") + " " + data.Field < string > ("Child#1 Part Number"));
}
Table like (Gridview sourced from a datatable) :
I am starting with linq and wondering if anybody knows how to add a select to the index of the rows picked after the condition of doing the groupby method from the code above.... this gives as outcome :
parent partnumber: GEC1H-PCB-00081-01 child partnumber: GEC1J-SW3555L11
parent partnumber: GEC1H-PCB-00091-01 child partnumber: GEC1J-SW3555L12
parent partnumber: GEC1H-PCB-00091-01 child partnumber: GEC1J-SW3555L11
and what I am looking is to identify the rows for which childpartnumber have a parentnumber column and that parent number be the first and omit the repeated ones like the rows of the following image:
Desired returned rows:
Any help will be most appreciated, Thanks