sort image or style on data grid

B

Brian Henry

is there a way to put a style or marker image on the header of a data grid
in asp.net to mark that this is the column being sorted on? thanks
 
S

Steven Cheng[MSFT]

Hi Brian,

As for your questions on marking a certain columns' header in webform
datagrid when the certain columns is being sorted on, here are my
suggestions:

All the WebForm DataGrid's Column are dervied from the
System.Web.UI.WebControl.DataGridColumn base class. This class has three
properties which can help set the column's header style feature, they are

HeaderImageUrl========== Gets or sets the location of an image to display
in the header section of the column.

HeaderStyle ============Gets the style properties for the header section of
the column.

HeaderText============ Gets or sets the text displayed in the header
section of the column.

Here is the reference in MSDN:
#DataGridColumn Properties
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIWebContro
lsDataGridColumnPropertiesTopic.asp?frame=true

And the "HeaderStyle" property is especially good since it contains many
sub members such as BackColor or BorderColor....

Thus, in the DataGrid's SortCommand event, we can retrieve the certain
columns reference from the
DataGrid.Columns collection and set any of the above three properties of
the sorted column. How do you think of this?


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
B

Brian Henry

I know about the properties of the column header, but how I get which column
it is working with from the sort event I'm not sure of
 
S

Steven Cheng[MSFT]

Hi Brian,

Thanks for your response. As for how to get the column that is on sorting
in SortEvent, this is done by the
System.Web.UI.WebControls.DataGridSortCommandEventArgs e
argument pass into the DataGrid's SortCommand event,
it contains a member property called "SortExpression", this field just
contains the
"SortExpression" of the certain Column which is being sorted. We can set
the "SortExpression" of each column in datagrid at design time.

#DataGridColumn.SortExpression Property
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIWebContro
lsDataGridColumnClassSortExpressionTopic.asp?frame=true

And here are some related reference in MSDN on using the Datagrid's sort
feature:

#DataGrid.SortCommand Event
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
lsdatagridclasssortcommandtopic.asp?frame=true

#Adding Sorting to a DataGrid Web Server Control
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskAddingSortingToDataG
ridWebControl.asp?frame=true


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
J

Joe Fallon

You can inject a Label control after the Header text control of the Sort
column.
Use the Item Data Bound event for this.
The label will just display " 5" or " 6". The space gives you a little
separation fromthe header text.
But the Font is Wingdings, x-small.
(this gives you an up or down triangle.)

I don't have any code samples handy but I use this trick and it works
nicely.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top