For a special requirements, we have created our own HTML table it works like a grid view. It gets its data from a DataTable and populates the TD and TR cells
We want to implement the Grouping functionality just like the grid view, where we specify the column name and all the values are grouped.
How can I perform the grouping directly in the DataTable and then output the rows as it is ? Can I use Linq ? Please help by directing towards an example.
You could try converting your
DataTabletoIEnumerableusingAsEnumerable(make sure you add a reference to System.Data.DataSetExtensions).Then use GroupBy to group your data. It will return
IEnumerable<IGrouping<TKey, TSource>>where eachIGrouping<TKey, TElement>object contains a collection of objects and a key. Example:Update:
You may group by using multiple fields (see example) or by nesting them (see example)