2010-02-03 60 views

回答

0

有这个CodeProject上的条目:Fixed Header in ASP.NET DataGrid

+0

表达式(this.offsetParent.scrollTop); 在Firefox和Chrome上有问题 – 2010-02-03 15:31:16

+0

在CodeProject站点给出的代码在Firefox中都不适用于我。我仍在寻找答案。 – bgmCoder 2012-12-21 16:49:02

1

我工作过一段时间,在这并放弃了让所有的浏览器的CSS工作。尽管不是一个简单的方法来实现这一点,但只需要有两个不同的表格,其列宽匹配。第一个表包含标题,第二个表包含内容并且可滚动。

我用jQuery使所有的列宽匹配。

对于一个完整的说明,请参见此篇:Scrollable DataGrid table with Fixed Header with jQuery

0

为了解决这个问题,我放置在原始上方的第二数据网格,我的尺寸的所有列在两个数据网格相等。在显示数据的数据网格中,我将标题设置为不显示。在后面的代码中,我将顶级数据网格绑定到空数据表,并设置绑定字段以在空时显示标题。

<div style="padding-bottom:2px"> 
 
<asp:GridView id="RoleListHeader" runat="server" AutoGenerateColumns="false" showheaderwhenempty="True" showheader="true" height="20px" width="350px" selectedrowstyle-height="20px" rowstyle-height="20px" headerstyle-height="10px" forecolor="#ff333333" backcolor="White"> 
 
\t <columns> 
 
\t \t <asp:TemplateField ItemStyle-Width="23"> 
 
        <ItemTemplate> 
 
        \t <asp:CheckBox></asp:CheckBox> 
 
\t \t \t \t \t </ItemTemplate> 
 
       </asp:TemplateField> 
 
\t \t <asp:BoundField DataField="SystemDesc" HeaderText="Role Description" ReadOnly="true" ItemStyle-Width="174"></asp:BoundField> 
 
\t \t <asp:BoundField DataField="EndDate" HeaderText="EndDate" ReadOnly="true" ItemStyle-Width="153"></asp:BoundField> 
 
\t </columns> 
 
</asp:GridView> 
 
</div> 
 
<div style="max-height:300px;overflow:auto"> 
 
<asp:GridView id="RoleList" runat="server" AutoGenerateColumns="false" showheaderwhenempty="True" showheader="false" height="0px" width="350px" selectedrowstyle-height="20px" rowstyle-height="20px" headerstyle-height="10px" forecolor="#ff333333" backcolor="White" rowstyle-horizontalalign="Center" rowstyle-borderstyle="Solid" rowstyle-bordercolor="#ff404040"> 
 
\t <columns> 
 
\t \t <asp:TemplateField ItemStyle-Width="23"> 
 
        <ItemTemplate> 
 
        \t <asp:CheckBox runat="server" OnCheckedChanged="GVChkBox_CheckChanged" AutoPostBack="true"></asp:CheckBox> 
 
\t </ItemTemplate> 
 
       </asp:TemplateField> 
 

 
\t \t <asp:BoundField DataField="SystemDesc" HeaderText="Role Description" ReadOnly="true" ItemStyle-Width="174"></asp:BoundField> 
 
\t \t <asp:BoundField DataField="EndDate" HeaderText="EndDate" ReadOnly="true" ItemStyle-Width="153"></asp:BoundField> 
 
\t \t <asp:BoundField DataField="ADHSystemId" ShowHeader="false"></asp:BoundField> 
 
\t </columns> 
 
</asp:GridView> 
 
</div>