Friday, July 17, 2009

How to Make SPGridView To Have Same Look And Feel Of The Out Of The Box SharePoint List View

When you attempt to develop a Web Part that uses an SPGridView control, you’ll notice the following differences to your SPGridView look and feel compared to the out of the box SharePoint List View:

  • SPGridView font type is Verdana, out of the box SharePoint List View font type is Tahoma
  • Font size and colour different
  • No alternating styles for items
  • Header style, pager styles, etc.

Screenshot below shows the differences:

 image

If you’re good in CSS and HTML, then you’ll find CSS Reference Chart for SharePoint 2007 is helpful and you should be able to change your SPGridView styles to have the same look and feel of of the out of the box SharePoint List View.

Instead of doing above you can assign the WebPart.UseDefaultStyles of your Web Part to false. See code below:

protected override void CreateChildControls()
{
    this.UseDefaultStyles = false;

By setting the UseDefaultStyles to false, your SPGridView styles will have the same look and feel of the out of the box SharePoint List View. See screenshot below:

image

Please note that UseDefaultStyles only applicable for SharePoint Web Part and not ASP.NET Web Part – for ASP.NET Web Part please use SPChromeSettings.UseDefaultStyles.

No comments: