2010-09-10 60 views
1

我的GridView与15岁及以上的列, 我需要使用下面的CSS冻结GridView的头:电网滚动在ASP.NET中冻结GridView标题?

.container 
     { 
      overflow: auto; 
     } 
     /* Keep the header cells positioned as we scroll */ 
     .container table th 
     { 
      position: relative; 
     } 
     /* For alignment of the scroll bar */ 
     .container table tbody 
     { 
      overflow-x: hidden; 
     } 

身体很好,但, 我的gridview的头不滚动Y上轴。

我的网格视图代码如下。

<asp:gridview id="RadGrid1" runat="server" borderstyle="None" borderwidth="1px" 
    gridlines="Both" autogeneratecolumns="true" onrowcommand="OnSelectedChanged" 
    rowstyle-wrap="false" rowstyle-cssclass="container" 
    onrowdatabound="RadGrid1_RowDataBound" datakeynames="DocID,DocumentName"> 
     <headerstyle cssclass="container" backcolor="LightBlue" wrap="false"  
      horizontalalign="Center" verticalalign="Middle" /> 
     <selectedrowstyle backcolor="Red" wrap="false" /> 
     <columns> 
     <asp:TemplateField> 
      <HeaderTemplate> 
       <input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" 
        runat="server" type="checkbox" /> 
      </HeaderTemplate> 
      <ItemTemplate> 
       <asp:CheckBox ID="chkSelect" runat="server" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:ButtonField ButtonType="Link" HeaderText="View" Text="View" CommandName="view" /> 
     <asp:ButtonField ButtonType="Link" HeaderText="Activity" Text="Activity" CommandName="activity" /> 
     </columns> 
</asp:gridview> 

回答

2

文章:Grid View with fixed header

For the gridview to freez the header

div#gridPanel 
{ 
    width:900px; 
    overflow:scroll; 
    position:relative; 
} 


div#gridPanel th 
{ 
    top: expression(document.getElementById("gridPanel").scrollTop-2); 
left:expression(parentNode.parentNode.parentNode.parentNode.scrollLeft); 
    position: relative; 
    z-index: 20; 
} 


<asp:Panel ID="gridPanel" runat="server" Height="200px" Width="100px" ScrollBars="Auto"> 
    asp.net grid view 
+0

感谢伟大工程。 – Ramakrishnan 2010-09-10 11:38:16

+0

林蛙,但这不是与IE 8版本,我该怎么做才能获得网格标题冻结在IE8 – Ramakrishnan 2010-09-13 05:30:51

+0

这可以在面板中滚动选项,但Gridview顶行或标题不会冻结在IE9 ... – Interstellar 2014-01-28 15:59:03