Wednesday, December 5, 2007

MOSS 2007 Overrides GridView Header in Web Part

I had created a Web Part with a GridView and explicitly set the header background color to dark blue and the forecolor to white.

     <asp:GridView ID="UserGroupsTable" runat="server" >
          lt;HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
     </asp:GridView>

Unfortunately, SharePoint overrode the style somehow with the core.css file. After a bit of troubleshooting in SharePoint designer, I got it working by overriding the CSS for the web part page.

     .ms-propertysheet th
     {
          color:white;
     }

For more information on MOSS 2007 CSS, check out Heather's site:

Heather Solomon - CSS Reference Chart

4 comments:

  1. Nice Post. Couldn't figure this out at all. Your solution worked great but it overrides again when i click a button. I guess there are more style to override?

    ReplyDelete
  2. I don't know if this is the same problem, but if you are mixing AJAX and SharePoint, this may be part of the problem. Despite what Microsoft might say, patching SharePoint with SP1 doesn't make it fully compatible with AJAX. I have found that things like the ModalPopupExtender don't always work as expected, especially when you are trying to revert back to a previous style. I have had to explicitly change the style back on these occasions. Here is a simple example you can try. Just change MyGridViewId to the id of your GridView and then stick this on your page.

    <input type="button" onclick="javascript:document.getElementById('<%= MyGridViewId.ClientID %&gt').rows[0].style.color = 'Red';" value="Change Header To Red" />

    ReplyDelete
  3. I'll try that again...

    <input type="button" onclick="javascript:document.getElementById('<%= MyGridViewId.ClientID %>').rows[0].style.color = 'Red';" value="Change Header To Red" />

    ReplyDelete
  4. Thanks!! That was exactly my situation. I was using the gridview inside of an ajax.net update panel. After some playing around I found out that if you simply override the "ms-propertysheet th" class OUTSIDE of the update panel, everything is fixed. Thanks for the reply!!!
    Mason Prewett
    mason.prewett@key2consulting.com

    ReplyDelete