469,319 Members | 2,421 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

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 3563
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 zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.