我有一个比我的aspx页面宽的gridview,所以我需要gridview的标题用水平滚动条滚动,但用垂直滚动条保持固定,我该如何实现?请帮忙?经过大量谷歌搜索后,我在将网格放置在 div 窗格中后尝试了各种 css 类,但这会同时锁定标题,水平和垂直。请帮助我仅在垂直滚动上修复标题。
我的 aspx 页面的一部分
<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 my css for this:
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');
}