sorting dataset
and I am facing the same issue.
I am designing a report. I have fill a dataset with the results from a query. From the results, I used to set the value from the items into an array and display on the aspx page in a table form. The reason why I don't use Datagrid or Gridview is because the table has to be design where the column headers has 2 or more rows and some columns need to be merged using colspan and rowspan. The HTML table also can provide me with the hover function for Alternate Text which is dynamic change for each column and rows. ASP.NET controls are lack in these features as I know. I also have linkbutton inside a cell with another static label.
My problem here is that I want to sort the rows of records from the table. My idea is to add linkbutton for the column header title so when click, the rows will be sorted as Ascending or Descending.
I have at least 7 columns to be sorted. If I have to modify the stored procedure then I need to pass in 7 parameters together with the Sort Order (Asc/Desc) for each parameter which will make the stored procedure become long and complicated. I have tried DefaultView property but the dataset is not sorted.
Expand|Select|Wrap|Line Numbers
- Protected Sub lnkSortRegion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSortRegion.Click
- SetParams()
- GetDataset()
- If lnkSortRegion.Text = "A-Z" Then
- dataset1.Tables(0).DefaultView.Sort = "Region"
- lnkSortRegion.Text = "Z-A"
- Else
- dataset1.Tables(0).DefaultView.Sort = "Region Desc"
- lnkSortRegion.Text = "A-Z"
- End If
- PopulateDataToArray()
- End Sub