Change Header color of sorted column in datagrid in asp.net

Hi all,

Want some help from u guys reg Datagrid in asp.net using vb.net as codebehind.

I want to change color of column after sorting in datagrid.
I tried on itemdatabound event of datagrid but no success.

It will be gr8 if anybody can solve my above query.

Code is
On itemdatabound event for datagrid
 Dim dv As DataView = CType(Dgtask.DataSource, DataView)
Dim dc As DataColumnCollection = dv.Table.Columns
        If e.Item.ItemType = ListItemType.Header Then
            If ViewState("SortExpression") <> "" Then
               'e.Item.Cells(dc.IndexOf(dc(ViewState("SortExpression")))).BackColor = Red
               e.Item.Cells(dc.IndexOf(dc(ViewState("SortExpression")))).ForeColor = White
             End If

Waiting for ur response.

Thnks & Rgds.
khacharnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HeadspaceCommented:
if you're using bound columns, and the sort expression is the same name as the header text, you could use something like this to change the column properties right in the sortcommand routine:

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
        Dim dv As New DataView(Session("dt"))
        dv.Sort = e.SortExpression
        DataGrid1.DataSource = dv
        DataGrid1.DataBind()
        Dim col As DataGridColumn
        For Each col In DataGrid1.Columns
            If col.HeaderText = e.SortExpression.ToString Then
                col.ItemStyle.BackColor = Color.Red
                col.ItemStyle.ForeColor = Color.White
            End If
        Next
    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HeadspaceCommented:
thx modulo : )
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.