RSS Feed Feed your read!

Bookmark and Share







Tag Cloud

ASP.NET Generic, Best Practices, Business Intelligence, Freeware Releases, InfoPath, Infrastructure, jQuery, Lunch & Learn Events, Project Server, Random, Reporting Services, Search, SharePoint Administration, SharePoint Business Analysis and Project Management, SharePoint Development, Silverlight, Social Networking, Speaking Events, White Paper Releases, Workflow Foundation,

Archives

June 2007 (3)
August 2007 (1)
November 2007 (2)
February 2008 (2)
April 2008 (5)
May 2008 (7)
June 2008 (8)
July 2008 (7)
August 2008 (3)
September 2008 (7)
October 2008 (1)
November 2008 (3)
December 2008 (3)
January 2009 (7)
February 2009 (5)
March 2009 (10)
April 2009 (2)
May 2009 (6)
June 2009 (3)
July 2009 (4)
August 2009 (6)
September 2009 (3)
October 2009 (9)
November 2009 (10)
December 2009 (1)
January 2010 (1)
February 2010 (3)
March 2010 (6)
April 2010 (2)
May 2010 (3)
June 2010 (4)
July 2010 (3)

Setting the CSS on a SPGridView Programmatically 

Tags:

Random topic – as you all know, it is well worth your time to use the SPGridView control because you can build really neat looking Data Grids from within SharePoint, that LOOK a lot like SharePoint – eg:

 

 

However, I had some specific requirements on colors/fonts and I needed to set a custom CSS class to my grid's CssClass property. I was having trouble getting this to work because it appeared the SPGridView kept over riding my changes within CreateChildControls. So, I overwrote OnPreRender and it worked! Here's my code:

 

public class SomeWebPart: System.Web.UI.WebControls.WebParts.WebPart

{

    SPGridView grid;

 

    protected override void OnPreRender(EventArgs e)

    {

        base.OnPreRender(e);

        grid.CssClass = "works";

    }

 

    protected override void CreateChildControls()

    {

        base.CreateChildControls();

 

        grid = new SPGridView();

 

        //grid.CssClass = "does't work";

//grid.Attributes["class"] = "doesn't work";

 

        // add columns, etc.

 

        this.Controls.Add(grid);

    }

}

 

 

Seems like the base class sets CSS and style propers in pre render – I guess that makes sense J

 

Phil

 
Posted by BENDER\pwicklund on 4-Aug-09
0  Comment  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments

Bookmark and Share

Note: Facebook no longer sends notifications for comments, so it may be a number of days before I see your post. For urgent matters, click "Contact Me" on the top nav. More info: Click Here.