【问题标题】:Forcing Gridview Header font bold to false in ASP.NET在 ASP.NET 中强制 Gridview Header 字体粗体为 false
【发布时间】:2015-06-13 01:44:34
【问题描述】:

我在强制 gridview 标题“取消粗体”时遇到问题。我尝试将 Gridview 参数用于标题字体样式,但它并没有真正起作用。不幸的是,我尝试过的所有其他方法都不起作用。

  1. 使用 CSS 类
.headercell

      {

       font-weight: normal;

       font-size: 12px;

       font-family: "Franklin Gothic Book"

      }
  1. 以编程方式使用行数据绑定

    If e.Row.RowType = DataControlRowType.Header Then
        For i = 0 To GridView1.Columns.Count - 1
            GridView1.Columns(i).HeaderStyle.Font.Bold = False
        Next
    End If
    

将 gridview 标题设置为非粗体最有效的方法是什么?

更新(ASPX 代码):

   <asp:GridView ID="GridView1" runat="server" BackColor="White" 
     BorderColor="#333333" BorderStyle="Solid" BorderWidth="2px"
     CellPadding="3" Font-Bold="false" Font-Overline="False" 
     Font-Size="Small" Font-Underline="False" HtmlEncode="false">
      <RowStyle ForeColor="#000066" Height="23px" HorizontalAlign="Center" 
         VerticalAlign="Middle" />
      <FooterStyle BackColor="White" ForeColor="#000066" />
      <PagerStyle BackColor="White" ForeColor="#000066"
         HorizontalAlign="Left" />
       <SelectedRowStyle BackColor="#669999" Font-Bold="True"
         ForeColor="White" />
        <HeaderStyle BackColor="#002851" Font-Bold="False" 
          CssClass="headercell" ForeColor="White" HorizontalAlign="Left"
          VerticalAlign="Middle" />
      <Columns>
       <asp:TemplateField HeaderText="STATUS" ShowHeader="False"
          Visible="True">
          <ItemTemplate>
           <asp:Button ID="Btn1" runat="server" CommandArgument='<%#
           DataBinder.Eval(Container, "RowIndex") %>'
           CommandName="Btn1_cmd">                                                                    

   </ItemTemplate>
  </asp:TemplateField>
  </Columns>
 </asp:GridView>

【问题讨论】:

  • 你也可以在 Template field 上设置 aspx 像这样&lt;asp:TemplateField HeaderText="Id" HeaderStyle-Font-Bold="false"&gt;
  • 对于模板字段,我使用了该代码。但是,在自动生成的列上,我无法将标题 font.bold 设置为 false。
  • 您需要设置AutoGeneratedColumn = false。如果您的Header 是固定的,则可以使用上述方法。向我们展示 Gridview aspx 的代码。以及您想要将字体粗体设置为 false 的位置。
  • 不幸的是,我无法设置 AutoGeneratedColumn = false 因为 gridview 中的列是动态的(用户输入)。这就是我尝试使用 RowDataBound 以编程方式设置样式的原因。
  • 能否展示gridview的aspx代码,以便我们更好地为您提供帮助

标签: css asp.net vb.net gridview header


【解决方案1】:

您可以在您的&lt;asp:BoundField /&gt; 上使用HeaderStyle-Font-Bold,因此只需将其设置为 false,如下所示

HeaderStyle-Font-Bold="false"

【讨论】:

    【解决方案2】:

    在你的gridview中添加一个名为“gvstyling”的CssClass

    像这样写一个css...

        .gvstyling th
        {
            font-size: 12px;
            font-weight: normal;
        }
    

    【讨论】:

      【解决方案3】:

      试试下面:

        th {
              font-weight: normal;
          }
      

      【讨论】:

      • 我尝试在 HeaderStyle 和 GridView CSS 中插入相同的 CssClass(上面的 .headercell)。但它不起作用
      【解决方案4】:

      这是我添加到 Gridview 中的 cssclass:

       .Grid, .Grid th, .Grid td
         {
        border-color: #CCCCCC;
        font-family: Franklin Gothic Book; 
        font-size: 12px;
        font-weight: normal; 
         }
      

      在源代码中,我只是将 CssClass="Grid" 添加到 Gridview 中(不在标题 cssclass 中)。

      【讨论】:

        猜你喜欢
        • 2016-02-23
        • 1970-01-01
        • 2011-08-21
        • 2020-08-08
        • 2021-08-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多