A most common question in many of the newsgroups and message board is "how to have a scrollable DataGrid" in a web page. In this article we are going to see how to create a scrollable DataGrid in a web page. By default DataGrid (Web Server Control) Doesn't Provide Any Features for Scrolling. But this Can Be Done with Help of Cascading Style Sheet (CSS Contains a Property Called "Overflow" Which Can Used for this purposes.
Scrollable DataGrid
You can add a vertical scrollbar to a DataGrid by placing the DataGrid within a div tag with a fixed height and Overflow property. Overflow property is to manage the content of the object when the content exceeds the height or width of the object. So when the rows exceed your specified height a scrollbar will appear. The overflow attribute should be set either to auto or scroll. Auto displays a scrollbar only if the content is clipped (that is, the DataGrid extends beyond the specified height). With scroll, the scrollbar Is Displayed Regardless of WHether The DataGrid's Height Exceeds The Specified Height. for more details on overoverflow property,
Http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/overflow.asp
Code Snippet for Scrollable DataGrid IS,
Now we know how to create a scrollable DataGrid in a web page. However, when scrolling through the DataGrid, the header columns would not be visible, since they will also scroll along with other rows. Ideally, when displaying a scrollable DataGrid we want to Have the header columns fixed, and only the body of the datagrid scrolling.scrollable DataGrid with fixed header
Scrollable DataGrid with fixed header can be created in the same way like Scrollable DataGrid. This can be accomplished by having DataGrid within Div tag whose overflow attribute is set to auto or scroll. However to have fixed headers, what we can do is hide the Scrollable DataGrid's headers. This can be done by setting "ShowHeader" property of DataGrid to false. Then create an HTML table above the Scrollable DataGrid's Div tab which displays the column. In the HTML table, we will have only one row which will be the header For Scrollable DataGrid. Code for Scrollable DataGrid with fixed header is,