473,385 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 3768
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

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

Similar topics

0
by: Tom Hughes | last post by:
I want to change one field of all selected rows to a provided value. Problem 1 I am using the Binding Manager Base to bind the datagrid to the appropriate dataTable as recommended by KB817247....
4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
4
by: bep | last post by:
Hello What is the best way to sort an XmlDocument for display in a DataGrig? I can use Xpath with an XpathExpression, and a XpathNavigator. But this XpathNavigator object is of no use to me, I...
1
by: troyblakely | last post by:
I am having trouble sorting a datagrid. I have read numerous posts on this and other lists, and tried most of the suggestions, but none of them have worked for me yet. I populate a dataset from two...
1
by: Geraldine Hobley | last post by:
Hello, I have a problem whereby I have a datagrid and and extra field all bound to the same dataset. I can easily edit rows in the dataset by changing the bindingposition in the...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
3
by: serge calderara | last post by:
Dear all, Does anyone know how to bind a System.Collection.ArraysList object to a Dataset ? Thanks for your reply Regards Serge
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.