472,127 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Sort Dataset without binding to datagrid

2
I have read the following topic:
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
  1.     Protected Sub lnkSortRegion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSortRegion.Click
  2.         SetParams()
  3.         GetDataset()
  4.         If lnkSortRegion.Text = "A-Z" Then
  5.             dataset1.Tables(0).DefaultView.Sort = "Region"
  6.             lnkSortRegion.Text = "Z-A"
  7.         Else
  8.             dataset1.Tables(0).DefaultView.Sort = "Region Desc"
  9.             lnkSortRegion.Text = "A-Z"
  10.         End If
  11.         PopulateDataToArray()
  12.     End Sub
Expert there please help me. Thanks.
Mar 16 '09 #1
1 3702
Frinavale
9,735 Expert Mod 8TB
The Table.DefaultView property returns a DataView associated with the table.

It can be used for sorting, filtering, searching, editing, and navigation. When you do sorting, filtering, or editing on the DataView, it has no effect on the DataTable it is associated with. This lets you create multiple views of the DataTable without modifying the source.

This means that when you do your sorting and call your PopulateDataToArray() method, you need to use the DataView instead of the DataTable in your DataSet.

I'd recommend modifying your PopulateDataToArray() method so that it accepts a parameter: the data source that should be displayed.

-Frinny
Mar 16 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Tom Hughes | last post: by
4 posts views Thread by Steve B. | last post: by
7 posts views Thread by DC Gringo | last post: by
1 post views Thread by troyblakely | last post: by
1 post views Thread by Geraldine Hobley | last post: by
3 posts views Thread by serge calderara | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.