HighTechTalks DotNet Forums  

Datagrid e.SortExpression is wrong

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Datagrid e.SortExpression is wrong in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default Datagrid e.SortExpression is wrong - 06-09-2006 , 01:46 PM






I have a Datagrid with the first 4 columns as blank and without a Sort
Expression set. The remaining columns have the Sort Expression set.

The page stores a ViewState variable named "CurrentSort", that contains
the sort expression the user last selected. When the page is initially
loaded, this value is set to "ID", which is not one of the sort
expressions in my DataGrid.

I have the following code that generates and Up/Down arrow depending on
the sort:

(ItemCreated event)...
if (e.Item.ItemType == ListItemType.Header)
{
for (int i=0; i < this.dgData.Columns.Count; i++)
{
if (this._currentSort ==
this.dgData.Columns[i].SortExpression)
{
TableCell cell = e.Item.Cells[i];
System.Web.UI.HtmlControls.HtmlImage imgArrow = new HtmlImage();
imgArrow.Src =(this._sortDirection==enuSortDirection.soAscendin g ?
"images/up.gif" : "images/dn.gif");
imgArrow.Alt = (this._sortDirection==enuSortDirection.soAscending ?
"Sorted in Ascending order" : "Sorted in Descending order");
cell.Controls.Add(imgArrow);
break;
}
}

On initial load, no arrow is produced because the initial sort order is
not a column.

When the user clicks on a column, SortCommand is raised with the passed
e.SortExpression. The problem is, when the above code produces an
arrow, the column that is returned with the SortCommand event is for
the the next column in the grid, (Column ID + 1) instead of the column
that was clicked. If the above code did not produce an arrow, then
everything works fine.

I was able to determine that when the grid is generated with an arrow,
the "link" in the status bar shows "...ctl{#}..." where the {#} of the
column is correct when no arrow is present and column + 1 when an arrow
is present. It seems to add a number when I add an arrow.

This is all done in .Net 1.1.xxxx

Thanks to anyone that can shed some light on this problem...

Thanks,
Mike


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.