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