473,388 Members | 919 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,388 software developers and data experts.

DataGrid, SortCommand and toggled sorting

Hi,

I have an aspx page in which I am building a DataGrid control in the
code-behind dynamically. The DataGrid is declared along with BoundColumns and
bound to the datasource, then added to a panel control in the OnInit method
of the aspx Page. I am trying to implement a bidirectional sorting. I have a
SortCommand method which fires OK. I have followed the code example given on
the 4GuysFromRolla site, which reads the value from SortExpression and apends
either the ASC or DESC sort commands. When the event is captured first there
is no sort command so I append e.SortExpression with DESC as the default is
ASC. The problem is that when the event fires next the SortExpression doesn't
contain the ASC DESC command. I am sure this has something to do with the
ViewState as the DataGrid is being built at every round trip. Question is how
to get round this??
--
Gilkesy
Jun 29 '06 #1
3 3747
Use ViewState or hidden field on the page to store the last direction. Then
on post back you can access it and attach to the expression.

"Mark Gilkes" <ma*********@NOSPAMgmail.com> wrote in message
news:9C**********************************@microsof t.com...
Hi,

I have an aspx page in which I am building a DataGrid control in the
code-behind dynamically. The DataGrid is declared along with BoundColumns
and
bound to the datasource, then added to a panel control in the OnInit
method
of the aspx Page. I am trying to implement a bidirectional sorting. I have
a
SortCommand method which fires OK. I have followed the code example given
on
the 4GuysFromRolla site, which reads the value from SortExpression and
apends
either the ASC or DESC sort commands. When the event is captured first
there
is no sort command so I append e.SortExpression with DESC as the default
is
ASC. The problem is that when the event fires next the SortExpression
doesn't
contain the ASC DESC command. I am sure this has something to do with the
ViewState as the DataGrid is being built at every round trip. Question is
how
to get round this??
--
Gilkesy

Jun 29 '06 #2
Thanks for the reply, not sure the hidden field method is particularly
practical as don't forget the datagrid is dynamic and therefore there will be
n number of fields. I haven't used ViewState to manually add stuff before so
I'll have a look at that. I guess what I need is some sort of Page level
property that holds reference to a HashTable or some form of 'key' 'value'
pair structure. Thanks once again.
--
MG.
"Winista" wrote:
Use ViewState or hidden field on the page to store the last direction. Then
on post back you can access it and attach to the expression.

"Mark Gilkes" <ma*********@NOSPAMgmail.com> wrote in message
news:9C**********************************@microsof t.com...
Hi,

I have an aspx page in which I am building a DataGrid control in the
code-behind dynamically. The DataGrid is declared along with BoundColumns
and
bound to the datasource, then added to a panel control in the OnInit
method
of the aspx Page. I am trying to implement a bidirectional sorting. I have
a
SortCommand method which fires OK. I have followed the code example given
on
the 4GuysFromRolla site, which reads the value from SortExpression and
apends
either the ASC or DESC sort commands. When the event is captured first
there
is no sort command so I append e.SortExpression with DESC as the default
is
ASC. The problem is that when the event fires next the SortExpression
doesn't
contain the ASC DESC command. I am sure this has something to do with the
ViewState as the DataGrid is being built at every round trip. Question is
how
to get round this??
--
Gilkesy


Jun 30 '06 #3
Of course, the ViewState object is sufficient and holds 'key' 'value' pairs.
This is has done the trick. Although, now I have a very strange behaviour
occurring. In my dynamically built DataGrid I have a TemplateColumn
containing and ImageButton. In the page holding the DataGrid I have the event
handlers for ItemCommand and SortCommand. When testing the toggled sorting I
noticed that the ItemCommand stops firing if the columns are sorted more than
once, i.e. If you click the ImageButton after clicking the column headers
more than once the page refreshes but neither the ItemCommand or the
SortCommand event fires. This is almost as if the event delegate is lost for
the TemplateColumn on the second round trip. Anyone got ideas on this one?
Jun 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: xrow | last post by:
Hello I have a simple webservice / c# application that receives data from server and prints the data in the asp:datagrid control I have problem when sorting data in datagrid I have created...
1
by: melanieab | last post by:
Hi, I found an article that explains how to do the custom sorting. Here is what it says: .... Perhaps you want some custom sorting method to take effect. To do that, DataGrid provides you with...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
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...
3
by: Raymond Lewallen | last post by:
I have a modal dialog displaying a datagrid control. Click on the column header to sort the datagrid opens a new window with the following in the location: ...
1
by: Sameeksha | last post by:
Hello, I've a datagrid whose AllowSorting property is set to True. The datagrid is bound to northwind table suppliers. I've handled the SortCommand event of the datagrid control. But somehow the...
1
by: Mark Gilkes | last post by:
I have a DataGrid which I am adding to the page dynamically at the Init stage of the page load. The DataGrid has AutoGenerateColumns turned off, has BoundColumns and is bound to a DataView for...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
0
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...
0
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...

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.