- About us
One workaround is to have a separate table control to show the header elements and hide the actual header of the grid.Now put the grid inside a div or panel with scrollbar property.But that takes extra effort to have a proper alignment.Each cell of the header table should be aligned with each cell of the grid.The other work around is to fix the header of the grid in such a way that scrolling down shouldnt hide the header of the grid.Using stylesheet we can achieve that.
Add the following style in your code and assign the grid view or datagrid header style css.
"panelContainer" is the id of the panel . "Sys.UI.DomElement.getBounds(document.getElementById("panelContainer")).y " gives the exact Y location of the panel where we need to fix the header.25 pixel is the usual height of the header .That much of space we had to leave for the header so that its not going to eat up any space of the grid content.With the Panel control, we can control the width, height, and scrollable option. For our code example, we set the height as 300px, the width as 100%, and set the Panel to scroll while showing only the vertical scrollbars. Put your grid inside the panel.Now we have to assign the CSS class defined above to the GridView's HeaderStyle
<asp:Panel ID="panelContainer" runat="server" Height="300px" Width="100%" ScrollBars="Vertical">