How to Group by any Field a DataView

I get a list of departments, but some are repeted. I want to be able to group them without going to the SQL Statement. I want to group At the dataview level. It’s it possible? :confused:

void DeptDropDown(){
GetDataClass getData = new GetDataClass();
string PageID = Request.QueryString[“PageID”];
DataTable PressRelease=new DataTable();
PressRelease = getData.GetPressData(PageID);
DataView dv = new DataView();
dv = PressRelease.DefaultView;
dv.Sort = “DepartmentLabel”;
ddlMainCat.DataSource = dv;
ddlMainCat.DataValueField = “DepartmentID”;
ddlMainCat.DataTextField = “DepartmentLabel”;

No, I think :). Check out this link (found with a quick Google):

HOW TO: Implement a DataSet GROUP BY Helper Class in Visual Basic .NET

Out of curiosity, is there any reason why you wouldn’t go to the database for this? It’s a lot simpler than rolling-your-own GROUP BY helper (and, heck, it’s what databases are designed to do).

To answer your question, we are working on a Team, There was class already returning a table with all the fields so we can then do our own query and stuff. To be able to group I had to add another function to the class that will return a table with just department title and ID already grouped. I just wanted to do it on my end and utilize the same table in the page with out having to create another function in the class file, which mean I have to recompile the project and post the .dll files again.

I thought it would be great if we cannot only do dataview.sort but also so we don’t have to go back to the SQL statement and do it there. Unfortunately I end up creating another function in the class file and return what I needed. I thought about looking into dataset, but I didn’t have time to play around so I did the way I was trying to prevent. Everyone in the Team now have to apply my changes so we can all be synchronized with the .dll files.

I looked into the Dataset helper, but it’s way to much, and it’s more for the windows form and code behind. I’m not using code behind, just referencing a class page.