472,145 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 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 3675
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by xrow | last post: by
1 post views Thread by melanieab | last post: by
2 posts views Thread by Ken Tucker | last post: by
2 posts views Thread by enak | last post: by
7 posts views Thread by DC Gringo | last post: by
3 posts views Thread by Raymond Lewallen | last post: by
1 post views Thread by Sameeksha | last post: by
1 post views Thread by Mark Gilkes | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | 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.