Software Technology Tips

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.




background-color: #006699;

color: #ffffff;

height: 25px;

top: expression(Sys.UI.DomElement.getBounds(document.getElementById("panelContainer")).y-25);


 "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">
<asp:GridView ID="gvScrollableExample" runat="server">
<HeaderStyle CssClass="fixedHeader " />
This way we can fix the header at the top of the grid and scrolling down is not going to scroll the grid with the header.

Related Tags:


Author: Satyaprakash Sahu


Let us Connect!

Awards and Achievements

Red Herringcolor DeloitteFast50 DB ZInnov1   Nascome  DB Stpi

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login