I am facing an issue with my gridview on an aspx page. The gridview is wider than the page itself, so I want the headers of the gridview to scroll horizontally along with the content, while remaining fixed vertically. Can anyone help me achieve this? I have tried various CSS classes after placing the grid inside a div element, but they end up locking both the header horizontally and vertically. I need assistance in fixing the headers only for vertical scrolling.
This is a part of my aspx page:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<div runat="server" id="GridViewDiv" style="overflow:auto" >
<asp:HiddenField ID="BindOnPostBack" Value="1" runat="server" />
<asp:GridView Width="100%" ID="ProjectsGridView" runat="server" AutoGenerateColumns="false"
OnRowCreated="BudgetGridView_RowCreated" OnRowDataBound="BudgetGridView_RowDataBound" PagerSettings-Visible="true" PageSize="20"
AllowPaging="true" AllowSorting="true" RowStyle-BackColor="#E8EAF7" RowStyle-BorderColor="White"
RowStyle-Height="19px" RowStyle-Font-Size="11px" RowStyle-HorizontalAlign="Left"
RowStyle-VerticalAlign="Middle" RowStyle-Font-Names="Tahoma,Helvetica,Arial"
HeaderStyle-BackColor="#d1d5ef" HeaderStyle-Height="22px" HeaderStyle-HorizontalAlign="Left"
HeaderStyle-Font-Names="Tahoma,Helvetica,Arial" HeaderStyle-Font-Size="13px"
HeaderStyle-Wrap="false" HeaderStyle-Font-Underline="false" RowStyle-Wrap="false"
PagerSettings-Position="Top" DataKeyNames="ID">
and here is my css code:
div#GridViewDiv {
width: expression(document.getElementById("ctl00_contentPanel").style.width);
height: expression(document.getElementById("contentdiv").style.width);
overflow: scroll;
position: relative;
}
div#GridViewDiv th {
top: expression(document.getElementById("GridViewDiv").scrollTop - 2);
left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);
position: relative;
z-index: 50;
}
td.locked, th.locked {
position:relative;
left:expression((this.parentElement.parentElement.parentElement.parentElement.scrollLeft-2)+'px');
}