DataGrid, SortCommand and toggled sorting

G

Guest

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??
 
W

Winista

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.
 
G

Guest

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.
 
G

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top