Skip to content

SubSonic Scaffold control - a GridView with Class

Thu Mar 08 2007

So I've been able to dig my teeth into some hacking recently, and I've been wrestling with learning to use SubSonic in the process.

In dealing with the scaffold control I ran into a funny issue: none of the exposed properties on the scaffold control will output any style info of the GridView that the control uses (that I could figure out anyways). I ended up with black text on a black background. 😕 Seeing as I have the source, I decided to give the scaffold control's GridView a little class...hello GridViewCssClass property! I set it up just like the EditTable*CssClass properties, just a string property, with similar attributes to the other properties hanging around there:

[Description("Sets the CSS class used by the gridview.")]
//CDF: just to have something to start with.
public string GridViewCssClass {
	get { return _gridViewCssClass; }
	set { _gridViewCssClass = value; }

Then, in the CreateGrid method make it actually do something:

private void CreateGrid()	{
			Label lblTitle = new Label();
      lblTitle.Text = "<h2>" + schema.Name + " Admin</h2>";

      grid.ID = "grid";
	    grid.CssClass = this.GridViewCssClass;


      if (!Page.IsPostBack) {

			//add a column to the grid for editing

And now I can declaratively set the CssClass that the GridView uses to, oh, say, .whitetext 😃

💾 May the source be with you. v3.2.409