2010-02-03 107 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>