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.
 
.fixedHeader

{

font-weight:bold;

position:absolute;

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 " />
</asp:GridView></asp:Panel> 
 
 
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:

ASP.NET

Author: Satyaprakash Sahu

ASP.NET

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login