filtering duplicate records from dataset
Posted on 2003-03-26
I have a datagrid filled with a dataset, and some drop-down lists that I use to filter the rows based on certain columns. It's easy enough to fill the drop-downs with all of the possible values for a column with its own select statement, but we really want to only list items that are available in the dataset - so I just set the dropdown list's datasource to the datagrid's dataset with DataTextField and DataValueField set to the appropriate columns in the dataset. But now I get a lot of duplicates since several rows in the dataset contain the same values for that particular column - how do you remove the dups from a list? I tried duplicating the datatable and removing all columns except the 2 I need for the drop-down, then adding a RowFilter of "DISTINCT" to its DefaultView but that didn't work. I sure wish you could just query a dataset or datatable - "SELECT DISTINCT column1,column2 FROM mydataset"... I would use SQL to do this but the dropdown contents will change when users filter the datagrid so most of the filtering is done in the master dataset with RowFilter, the entire contents are loaded on page load and after that it's all in ViewState.