473,769 Members | 4,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SortExpressio n 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 3770
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*********@NO SPAMgmail.com> wrote in message
news:9C******** *************** ***********@mic rosoft.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.SortExpressio n 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*********@NO SPAMgmail.com> wrote in message
news:9C******** *************** ***********@mic rosoft.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.SortExpressio n 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
9499
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 SortCommand event in my .aspx file for my datagrid DataGrid2 but I am not able to access my datarecord nor dataset from my SortCommand event. I recieve also an error when running with created event if don't change event method declaration to public void...
1
1490
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 an action to overload called "SortCommand." In the properties events for your DataGrid, select the "SortCommand" action and implement it with the method name of your choice... But when I go to the datagrid properties events, there is no action...
2
8498
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 just be missing something. Basically, I have a .aspx page that is very simple and has a simple datagrid. All code is in the .cs page for the datagrid (hence, I'm doing all datagrid work programmatically). The datagrid is populated from a SQL table...
2
2260
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 the bottom of the dg.) When I click on the pages nothing happens until I get to the last page. Then and only then is the last page displayed. If I go back through the pages the second to last page displayes the first page again.
7
2467
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
3
2126
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: javascript:__doPostBack('dgDataGrid$_ctl1$_ctl1','') instead of actually posting back to the modal dialog and sorting the datagrid. ItemDataBound, ItemCommand events both work fine, only the SortCommand is producing this unwanted behavior.
1
1583
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 code is not working. The SortCommand event handler is called, but the data shown in the grid is not sorted. I've written the following code in the asp.net web appl. private void Page_Load(object sender, System.EventArgs e) { if...
1
3085
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 its’ data source. I have also added a TemplateColumn which is defined in a derived class and contains an ImageButton. The derived TemplateColumn class contains an event handler for DataBinding and in this handler I assign the ImageButton ID. The...
0
2091
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
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
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.