In the process of developing a ASP.net project, the customer asked us to make the header of all DataGrid tables look like Excel tables, and when the table had lots of data, we could pull down the scroll bar and keep the header fixed. After the search on the internet found the following relatively simple method. The specific application is as follows:
1. Add a class to the CSS
. fixheaderstyle {
font-size:9pt;
Vertical-align:middle;
Text-transform:capitalize;
font-family: "Arial", "Helvetica", "Sans-serif";
height:25px;
Background-color: #ecf4fe;
Text-align:center;
Text-decoration:none;
position:relative; -The necessary
Top:expression (THIS.OFFSETPARENT.SCROLLTOP)--Necessary
}
On the page, similar code such as:
<div style= "Overflow:auto; width:100%; height:300px "align=" Center ">
<asp:datagrid Id=grdcurratevoy runat= "Server" width= "100%" visible= "True" >
<itemstyle cssclass= "ItemStyle" ></ItemStyle>
<pagerstyle cssclass= "PagerStyle" ></PagerStyle>
</asp:DataGrid>
</DIV>
It's done.