【发布时间】:2014-08-05 17:35:24
【问题描述】:
我在Panel 中有以下GridView,其中overflow: scroll 允许滚动:
<asp:Panel runat="server" ClientIDMode="Static" ID="pnlScroll" CssClass="pnlScroll">
<asp:GridView AlternatingRowStyle-BackColor="#E2E2E2" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="There is no data to display" OnRowDataBound="yourTasksGV_RowDataBound">
<HeaderStyle CssClass="yourTasksGVHeader" />
<Columns>
<asp:BoundField DataField="Task Name" HeaderText="Task Name" SortExpression="TaskName" ItemStyle-Width="25%" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="DepartmentName" ItemStyle-Width="25%" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="TheStatus" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Due Date" HeaderText="Due Date" SortExpression="DueDate" ItemStyle-Width="20%" ItemStyle-CssClass="taskTableColumn" />
<asp:HyperLinkField Target="_blank" DataNavigateUrlFields="Link" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Details" SortExpression="TaskDetails" ItemStyle-Width="15%" ItemStyle-CssClass="taskTableColumn" />
</Columns>
</asp:GridView>
</asp:Panel>
CSS:
#yourTasksGV {
width: 100%;
padding: 0;
margin: 0 auto;
}
#yourTasksGV th {
padding: 8px;
border-bottom: 2px solid black;
background: url(../theImages/gridHdr.png) repeat-x;
}
#yourTasksGV th a {
text-decoration: none;
}
#yourTasksGV th a:hover {
text-decoration: underline;
}
#yourTasksGV td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #E2E2E2;
border-right: 1px solid #E2E2E2;
}
.yourTasksGVHeader {
position: relative;
top: expression(this.offsetParent.scrollTop);
z-index: 10;
}
.taskTableColumn a {
text-decoration: none;
}
.taskTableColumn a:hover {
text-decoration: underline;
}
.pnlScroll {
height: 750px;
display: inline-block;
overflow-y: scroll;
overflow: scroll;
/* IE */
scrollbar-base-color: #A0A0A0;
scrollbar-base-color: #A0A0A0;
scrollbar-3dlight-color: #A0A0A0;
scrollbar-highlight-color: #A0A0A0;
scrollbar-track-color: #EBEBEB;
scrollbar-arrow-color: #FFFFFF;
scrollbar-shadow-color: #A0A0A0;
scrollbar-darkshadow-color: #A0A0A0;
}
当我滚动时,当表格的其余部分滚动时,标题应该保持不变。但这并没有发生,因为我滚动标题时也会滚动并移出视图。
如何修改我的代码以使其正常工作? (我在IE8上测试)
【问题讨论】:
-
尝试从 .yourTasksGVHeader 中删除 top: 并添加 display: 块。
-
不,标题仍然随着内容滚动:/
-
我有一个非常相似的东西,刚刚验证它实际上不适用于 IE8(它是一个 Intranet 站点,我们使用的是 IE11)。
-
该死... IE8 的任何替代解决方案?
-
我以前使用过一些 javascript 解决方案,但我从未发现任何我特别喜欢的东西。 fixedheadertable.com 就是一个例子。我最大的抱怨是当表相对较大时,客户端的性能会受到影响。
标签: c# html asp.net gridview scroll