Change header text forecolor of sorted column

3 posts, 1 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 03 Jul 2012 Link to this post

    I'm not seeming to find anywhere where I can change the fore color of only the sorted header field. I'm using custom colors on the sort and I need to change the color of the text but only on the column that's sorted.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2012 Link to this post

    Hello,

    In order to change the header color on sorting, try the following code in Prerender event.
    C#:
    void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (RadGrid1.MasterTableView.SortExpressions.Count > 0)
        {
         foreach (GridSortExpression expression in RadGrid1.MasterTableView.SortExpressions)
         {
           GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
            headerItem[expression.FieldName].BackColor = System.Drawing.Color.Red;
         }
       }
    }
    For changing the entire column color on sorting, try setting the following.
    aspx:
    <SortingSettings SortedBackColor="Red"  />

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 05 Jul 2012 Link to this post

    I changed backcolor to forecolor as I was trying to change the text color, but it worked perfectly, here's the vb in case anyone else needs it.

    Protected Sub clientGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles clientGrid.PreRender
     
        If (clientGrid.MasterTableView.SortExpressions.Count > 0) Then
     
            For Each exp As GridSortExpression In clientGrid.MasterTableView.SortExpressions
     
                Dim headerItem As GridHeaderItem = TryCast(clientGrid.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem)
                headerItem(exp.FieldName).ForeColor = Drawing.Color.White
     
            Next 'for each
     
        End If 'if count > 0
     
    End Sub 'prerender
Back to Top