473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sort Dataset without binding to datagrid

2 New Member
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 3775
Frinavale
9,735 Recognized Expert Moderator Expert
The Table.DefaultVi ew 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 PopulateDataToA rray() method, you need to use the DataView instead of the DataTable in your DataSet.

I'd recommend modifying your PopulateDataToA rray() 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
1838
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. It works in all cases but one. If the field being changed is also one the user has selected as a sort column, then all but the first selections are missed. If I remove the sort from that column before or after
4
2829
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 form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
0
3490
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 after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. There is nothing crazy about the code. I used the designer to add the dataset and to do the...
7
2444
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 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here
4
2180
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 need a XmlDocument. So is there an easy way to convert an XPathNavigator object to an XmlDocument? And I could use a piece of Xstl to transform the doc. But this seems like a lot of work. I would have to load the Xslt from file, cache it, and...
1
1765
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 queries, then I want to sort the data and bind it to a datagrid. Regardless of what I have tried, the datagrid is populated with the unsorted data. Any assistance you have would be appreciated. I have attempted the sort using the dataview.sort...
1
1380
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 MyGrid_currentcellchanged event of Mygrid, using the following function Private Function GetBindingPosition(ByVal IntMatchValue As Integer, ByVal MyMatchField As String, ByVal MyDataTable As DataTable) As Integer Dim i As Integer = 0 Dim blnValueFnd As Boolean ...
17
2747
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 allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
3
3281
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
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.