c# - 仅在垂直滚动时卡住 gridview 标题

标签 c# asp.net css gridview scroll

我有一个比我的 aspx 页面更宽的 gridview,所以我需要 gridview 的标题随水平滚动条滚动,但在垂直滚动条上保持固定,我该如何实现?请帮忙?经过大量谷歌搜索后,我在将网格放入 div Pane 后尝试使用各种 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');
}

最佳答案

position:fixed; 属性将根据浏览器将组件固定到位。

关于c# - 仅在垂直滚动时卡住 gridview 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17562286/

相关文章:

javascript - 从导入的图标列表图像更改呈现的图标大小

c# 使用 linq 将 viewModel List 对象上的字符串属性串联起来显示在 MVC View 上

c# - 确定反射类型是否可以转换为另一个反射类型

C# DateTime求值问题

c# - 如何匹配文件内容中的正则表达式模式而不循环遍历文件中的每一行?

c# - 如何将 en-US 日期更改为 en-GB for asp.net?

asp.net:__doPostBack 有时不呈现

c# - 从物理文件实例化 IFormFile

javascript - 带有 !important 的 pre 标签中的 ng-style 不起作用

html - 一个表占用其他表中单元格的可用高度