【问题标题】:Data grid View header Height is changing at run time how to fix that?Datagridview 标头高度在运行时发生变化如何解决?
【发布时间】:2014-03-25 04:23:05
【问题描述】:

我在 ASP VB.net 中工作,我的 Gridview 与 SQL 数据源绑定。我必须在运行时添加/删除行。问题是当网格中没有项目时,标题本身占据网格的全高,即总高度根据行数拆分,但我需要修复标题和行高,

<asp:GridView ID="grdRequestItems" runat="server" AutoGenerateColumns="False" 
     Height="76pt" Width ="871px"  DataSourceID="SqlDataSource1" 
     style="font-size: 14pt;  table-layout :fixed;" 
     CellPadding="1" HorizontalAlign="Center" PageSize="5" DataKeyNames="TempID" ShowHeaderWhenEmpty="True" AllowPaging="True" >

colums 属性..

<Columns>
    <asp:BoundField DataField="Sno" HeaderText="Sno"    SortExpression="Sno">
    <HeaderStyle BackColor="#666666" ForeColor="White" Height="20px" Width="25px" 
     VerticalAlign="Top" Font-Names="Segoe UI"  HorizontalAlign="Center" 
         Font-Size="14pt" />

...........

其他属性是..

   <EmptyDataRowStyle Height="20pt" VerticalAlign="Top" />
   <HeaderStyle Font-Names="Segoe UI" Font-Size="14pt" Height="20px" 
      VerticalAlign="Top" HorizontalAlign="Center" />
   <RowStyle Height="20pt" VerticalAlign="Top" Wrap="True" BackColor="#E6F2FF"  
     FontNames="Segoe UI" Font-Size="12pt" />
   <SelectedRowStyle BackColor="White" Font-Names="Segoe UI" Font-Size="14pt" />
   </asp:GridView>

有人可以帮帮我吗?

【问题讨论】:

    标签: html asp.net css gridview


    【解决方案1】:

    从您的 GridView 定义中删除 height="76"

    另外,请考虑使用 CssClass 而不是通过属性指定样式。这是一个例子:http://www.etechpulse.com/2013/08/asp-gridview-css-style-sample-user.html

    【讨论】:

    • 它正在工作,谢谢 :)
    【解决方案2】:

    您应该尝试使用 CSS 而不是 Gridview 中的内联样式设置标题行的大小。

    <asp:GridView ID="grdRequestItems" runat="server" style="font-size:14pt;table-layout :fixed;height:76px;" 
    HeaderStyle-CssClass="FixedHeader" 
    >  
    
    <style type="text/css">
            .FixedHeader {
                position: absolute;
                font-weight: bold;
            }     
    </style>  
    

    【讨论】:

    • 我刚刚移动了网格的高度及其工作,感谢您考虑
    猜你喜欢
    • 2010-09-26
    • 2017-10-27
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 2020-03-07
    相关资源
    最近更新 更多