2012-10-25 35 views

回答

6

把電網中的股利或panel with scrollbar property。但是這需要額外的努力,有頭表的正確alignment.Each細胞應該是grid.The其他工作的aligned with each cell周圍是fix the header of the grid以這樣的方式scrolling down shouldnt hide the header內的網格。使用stylesheet我們可以做到這一點。

在代碼中添加以下樣式並指定網格視圖或數據網格標題樣式css

.fixedHeader 
{ 
    font-weight:bold; 
    position:absolute; 
    background-color: #006699; 

    color: #ffffff; 

    height: 25px; 

    top: expression(Sys.UI.DomElement.getBounds(document.getElementById("panelContainer")).y-25); 

} 

"panelContainer" is the id of the panel"Sys.UI.DomElement.getBounds(document.getElementById("panelContainer")).y "給出了我們需要的面板的確切Y位置fix the header .25像素是標頭的通常高度。 That much of space we had to leave for the header,這樣它就不會吃掉電網內容的任何空間。通過面板控制,我們可以控制width, height, and scrollable option。 對於我們的代碼示例,我們設置了height as 300px,the width as 100%,並設置面板滾動,同時只顯示vertical scrollbars。把你的網格panel.Now內,我們必須分配上述定義GridView的HeaderStyle

<asp:Panel ID="panelContainer" runat="server" Height="300px" Width="100%" ScrollBars="Vertical"> 
    <asp:GridView ID="gvScrollableExample" runat="server"> 
    <HeaderStyle CssClass="fixedHeader " /> 
    </asp:GridView></asp:Panel> 

這樣我們就可以解決在網格頂部的標題和向下滾動不會滾動的CSS類網格與標題。