Results 1 to 6 of 6

Thread: Formatting sorted header column in gridview

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Formatting sorted header column in gridview

    I have a gridview with sorting implement. Here is a bit of the code.

    Code:
                       <asp:GridView ID="gvDetails" runat="server" DataKeyNames="SSID" AutoGenerateColumns="False"
                            Width="100%" CssClass="GridHeadDisplay" OnRowDeleting="gvSSDetails_RowDeleting"
                            AllowSorting="true" OnSorting="gvSSDetails_Sorting" OnRowDataBound="gvSSDetails_RowDataBound">
                            <RowStyle CssClass="GridItemDisplay" />
                            <EmptyDataTemplate>
                                <asp:Label ID="Label1" runat="server">
                                        <font style="font-size: 10pt; font-family: Tahoma;" >No records Found</font>
                                </asp:Label>
                            </EmptyDataTemplate>
                            <Columns>
                                <asp:BoundField  DataField="OrganisationID" HeaderText="OrganisationID" Visible="False" />
                                <asp:TemplateField HeaderText="Organisation" SortExpression="OrgName">
    The grid has 4 columns. 2 of them you can sort on. But the text in those two column headers - that you click on to sort - is being formatted to look like a hyperlink. This formatting is not done by me - it seems to be happening itself.

    The whole header row is formatted by CssClass="GridHeadDisplay" - so I have a row with blue backgrounds to the cells with white text in them - apart from the two that you can sort on that look like the standard blue, underlined hyperlinks.

    How can I make the text in the two column header cells you can sort on look the same as the text in the other columns?

    Thanks for any help.

  2. #2
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    Re: Formatting sorted header column in gridview

    Try setting this attribute in the gridview tag:

    HeaderStyle-CssClass="YourHeaderCSSclass"

    like this:

    <asp:GridView I
    D="gvDetails"
    runat="server"
    DataKeyNames="SSID"
    AutoGenerateColumns="False"
    Width="100%"
    CssClass="GridHeadDisplay"
    OnRowDeleting="gvSSDetails_RowDeleting"
    AllowSorting="true" OnSorting="gvSSDetails_Sorting" OnRowDataBound="gvSSDetails_RowDataBound"
    HeaderStyle-CssClass="YourHeaderCSSclass"
    >

  3. #3
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: Formatting sorted header column in gridview

    I'm having a similar problem. I'm fairly certain that setting the HeaderStyle doesn't actually apply in this case. If I set HeaderStyle to something like "gridViewHeader", the generated HTML looks something like:

    <tr class="gridViewHeader">
    <th scope="col">
    <a href="javascript:__doPostBack(...snip...)">Last Name</a>
    </th>
    ...snip...

    The gridViewHeader class doesn't affect the style for the anchor tag. Here's what my gridViewHeader style looks like:

    .gridViewHeader
    {
    background-color:#C0C0FF;
    color:Navy;
    }

    The resulting text is not Navy. I tried adding these styles as well:

    A.GridViewHeader:link
    {
    color: Navy;
    }
    A.GridViewHeader:visited {
    color: Navy;
    }
    A.GridViewHeader:active {
    color: Navy;
    }
    A.GridViewHeader:hover {
    color: Navy;
    }

    That didn't do any good either. I also hooked OnRowDataBound for the gridview, and checked the cells in the DataControlRowType.Header row. I didn't see the anchor tag equivalent (Hyperlink control, I believe) in there, so I couldn't set the CssClass for the anchor tag that way.

    Does anyone have any more suggestions?

    Thanks,

    David

  4. #4
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: Formatting sorted header column in gridview

    Hah! Found it. Obviously I need to learn more about CSS. I was on the right track in my previous post. This is what I needed, though:

    .GridViewHeader A:link
    {
    color: Navy;
    }
    .GridViewHeader A:visited {
    color: Navy;
    }
    .GridViewHeader A:active {
    color: Navy;
    }
    .GridViewHeader A:hover {
    color: Navy;
    }

    Now my header looks like I want.

    David

  5. #5
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Formatting sorted header column in gridview

    This is an old thread but this doesn't work for me at all has this changed?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  6. #6
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Formatting sorted header column in gridview

    I have posted a solution to your thread on Changing Link Color.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width