【问题标题】:Fixed Column Headers For ASP.NET Gridview固定 ASP.NET Gridview 的列标题
【发布时间】:2012-10-24 18:11:40
【问题描述】:

我有一个 ASP.NET 面板,里面有一个 gridview。下面是它的标记:

<asp:Panel runat="server" ID="searchResultsPanel" CssClass="datagrid" ClientIDMode="Static" style="display:none; max-height:500px; max-width:700px; overflow:auto;" >
    <asp:GridView runat="server" ID="gridMemberInfo" AutoGenerateColumns="false" EmptyDataText="No Members Were Found." OnRowCommand="Command_SearchGrid" ShowHeader="true" ShowHeaderWhenEmpty="true" >
        <PagerSettings Visible="false" />
        <AlternatingRowStyle CssClass="alt" />
        <Columns>
            <asp:ButtonField ButtonType="Link" Text="Select" CommandName="SelectRow" />
            <asp:BoundField  HeaderText="PMI"                DataField="PMI" />
            <asp:BoundField  HeaderText="Product"            DataField="Product" ItemStyle-Width="110px"  />
            <asp:BoundField  HeaderText="County"             DataField="County" />
            <asp:BoundField  HeaderText="Last Name"          DataField="LastName" />
            <asp:BoundField  HeaderText="First Name"         DataField="FirstName" />
            <asp:BoundField  HeaderText="Currently Enrolled" DataField="CurrentlyEnrolled" ItemStyle-Width="50px" />
        </Columns>
    </asp:GridView>
</asp:Panel>

我有以下用于面板和网格视图的 CSS:

.datagrid table 
{ 
    border-collapse: collapse; 
    text-align: left; 
    width: 100%; 
} 

.datagrid 
{
    font: normal 12px/150% Arial, Helvetica, sans-serif; 
    background: #fff; 
    overflow: hidden; 
    border: 2px solid #006699; 
    -webkit-border-radius: 10px; 
    -moz-border-radius: 10px; 
    border-radius: 10px; 
}

.datagrid table td, .datagrid table th 
{ 
    padding: 3px 10px; 
}

.datagrid table thead th 
{
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #00A2F2), color-stop(1, #002C42) );
    background:-moz-linear-gradient( center top, #00A2F2 5%, #002C42 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00A2F2', endColorstr='#002C42');
    background-color:#00A2F2; 
    color:#FFFFFF; 
    font-size: 12px; 
    font-weight: bold; 
    border: none;
} 

.datagrid table thead th:first-child 
{ 
    border: 3px; 
}

.datagrid table tbody td
{ 
    color: #00496B; 
    font-size: 12px;
    font-weight: normal; 
}

.datagrid table tbody .alt td 
{ 
    background: #E1EEF4; 
    color: #00496B; 
}

.datagrid table tbody td:first-child 
{ 
    border-left: none; 
}

.datagrid table tbody tr:last-child td 
{ 
    border-bottom: none; 
}

为了让 gridview 与头元素一起呈现,我在后面的代码中执行此操作:this.gridMemberInfo.HeaderRow.TableSection = TableRowSection.TableHeader;

由于我将面板的溢出设置为自动,因此当 gridview 有很多行时我可以滚动。我现在想做的是固定标题行,以便在滚动时始终可以看到它。我尝试在.datagrid table thead th CSS 类中设置position:fixed;,但没有奏效。我尝试了其他几种选择,但没有运气。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: asp.net css gridview scroll panel


    【解决方案1】:

    你不能在 IE 上这样做,因为那里的 css 解释器不考虑thead。您将需要实现一个保存标题的 wapping div。或使用以前做过的:http://www.scientificpsychic.com/blogentries/html-and-css-scrolling-table-with-fixed-heading.html

    或者你可以看看:

    http://demos.devexpress.com/ASPxGridViewDemos/PagingAndScrolling/Scrolling.aspx

    取自堆栈答案:Fixed GridView Header with horizontal and vertical scrolling in asp.net

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-25
      • 2017-12-27
      • 2014-08-02
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2013-10-13
      相关资源
      最近更新 更多