BUG: ScrollableGrid Control

Published 08 January 04 10:44 AM | despos

Someone (thanks, David) pointed out a bug in my ScrollableGrid control from the January 2004 issue of aspnetPRO magazine. The control adds a frozen header and footer to a grid and makes the body of it scrollable using the overflow CSS attribute of recent browsers.

If the data source contains less rows than can fit into the fixed-height grid, then the actual height of each row is calculated proportionally. In other words, if you going to have a 100 pixel grid with only two rows to display, each row takes 50 pixels. Which obviously results in a bad looking grid.

The simplest workaround--at this time I'm not even sure a perfect workaround does exist--consists in overriding the DataGrid's Height property as follows:

  public override Unit Height
  {
   get {return (Unit) ViewState["TableHeight"];}
   set {ViewState["TableHeight"] = value;}
  }

Just add this code to mydatagrid.cs and recompile. It works now but it's not perfect. The scrollbar is not displayed and its reserved space is left blank. Not too bad, but not perfect either. 

You might want to modify the settings for the overflow style too and replace overflow:auto with overflow:scroll throughout the code of the mydatagrid.cs file. In this case, the scrollbars (both horz and vert) are always displayed, disabled if necessary.

You can't just know in a piece of server-side code about the client settings of the scrollbars. IE6 returns that info but you can access it only using DHTML.

 

Comments

# TrackBack said on January 7, 2004 11:43 PM:
# IanG said on January 14, 2004 07:41 AM:

Dino,

You mentioned in another post that you hoped to get the source code for the Scrollable Grid up onto www.codearchitects.com from start of January but it doesn't seem to be there...any chance this will be happening soon.

Many thanks.

# Naveen said on January 22, 2004 01:57 PM:

Dino,

Setting the the 'height' property of ItemStyle of the datagrid to a constant value resolves this issue.

# DinoE said on January 23, 2004 03:31 AM:

Sure. But I was just trying to avoid that :-)
I was looking for a solution that works in a rather automatic way.

# Brian said on June 30, 2004 02:40 PM:

Is there a way to put the datagrid in edit mode and scroll the datagrid to the position of the item that was placed in edit mode?

Leave a Comment

(required) 
(required) 
(optional)
(required)