Merge database cells in column B to map cells in column A in VB.NET

I have a table (data retrieved from an SQL database) in the form:

╔═══════╦══════════════╗ β•‘ Model β•‘ Manufacturer β•‘ ╠═══════╬══════════════╣ β•‘ A β•‘ 1 β•‘ β•‘----------------------β•‘ β•‘ A β•‘ 2 β•‘ β•‘----------------------β•‘ β•‘ A β•‘ 3 β•‘ β•‘----------------------β•‘ β•‘ B β•‘ 4 β•‘ β•‘----------------------β•‘ β•‘ B β•‘ 5 β•‘ β•‘----------------------β•‘ β•‘ C β•‘ 6 β•‘ β•‘----------------------β•‘ β•‘ D β•‘ 7 β•‘ β•‘----------------------β•‘ β•‘ D β•‘ 8 β•‘ β•‘----------------------β•‘ β•‘ D β•‘ 9 β•‘ β•‘----------------------β•‘ β•‘ D β•‘ 10 β•‘ β•šβ•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 

Each row is its own <tr> when I bind data to <asp:datagrid> . However, I need:

 ╔═══════╦══════════════╗ β•‘ Model β•‘ Manufacturer β•‘ ╠═══════╬══════════════╣ β•‘ A β•‘ 1 β•‘ β•‘ β•‘ 2 β•‘ β•‘ β•‘ 3 β•‘ β•‘----------------------β•‘ β•‘ B β•‘ 4 β•‘ β•‘ β•‘ 5 β•‘ β•‘----------------------β•‘ β•‘ C β•‘ 6 β•‘ β•‘----------------------β•‘ β•‘ D β•‘ 7 β•‘ β•‘ β•‘ 8 β•‘ β•‘ β•‘ 9 β•‘ β•‘ β•‘ 10 β•‘ β•šβ•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 

I spent a lot of time searching and tried several different things, most of which used LINQ. But my knowledge and understanding of LINQ is very small. I think (but I could be completely wrong), the closest I came from this question / answer: Linq query to combine the results of a cellular network? . My slightly modified version:

 Dim results = table.AsEnumerable().GroupBy(Function(x) x.Field(Of String)("Model")).[Select](Function(grouping) New With { .Key = grouping.Key, .CombinedModel = grouping.Aggregate(Function(a, b) a + " " + b) }).[Select](Function(x) New ModelRecord() With { .Manufacturer = x.Key.Manufacturer, .Model = x.CombinedModel }) 

But due to a lack of knowledge of LINQ, I don’t understand the "definition of a specific type to represent Row " (which creates a problem with ModelRecord() in my code).

At that moment, I was almost completely lost. Am I complicating things too much? Is this really wrong? Any help here would be greatly appreciated.

+4
source share
2 answers

This solution , which I mentioned in my comments on your question, works. Thanks for trying.

+1
source

Instead of using a DataGrid or GridView, I find it better suited for a repeater, where you better control the formatting of the data. Then you can load the data into the model dictionary with a list of manufacturers ( Dictionary<Model, List<Manufacturer>> ). After loading the object up, you determine how to display it in the repeater.

+1
source

Source: https://habr.com/ru/post/1484270/


All Articles