|
Creating a Scrollable DataGrid with a Fixed Header
By:
Scott Mitchell
|
Created: 2003-05-10
|
Last Updated: 2003-05-15
|
Printer-Friendly Version
In an earlier FAQ, Creating a Scrollable DataGrid, we saw how to create a scrollable DataGrid. However, when scrolling through the DataGrid, the header columns would not be visible, since they were not fixed. Ideally, when displaying a scrollable DataGrid we want to be able to have the header columns fixed, and only the body of the DataGrid scroll.
This can be accomplished with the ASP.NET DataGrid by surrounding the DataGrid with a If this seems a bit confusing, don't worry. Let's check out an example to see how this can be handled.
Note that first, a standard HTML
Off By a Bit Unfortunately, as you can see in this live demo, the header column doesn't line up perfectly with the DataGrid. This is because the displayed scrollbar pushes over the content of the DataGrid just a bit. In fact, if you remove the overflow: auto; style setting from the div tag, everything will line up just peachy.
I have not found out any way to get everything to line up precisely short of just tweaking the style properties of the
With this change, the new code becomes:
You can check out the new results in this live demo. Note that the "header column" and DataGrid body line up nicely.
|
Home | FAQs | Articles | About | My Blog | Buy the Book!
Copyright 2006, Scott Mitchell. All Rights Reserved.