在 ASP.NET 中强制 Gridview Header 字体加粗为 false

Forcing Gridview Header font bold to false in ASP.NET

我在将 gridview header 强制为 "unbold" 时遇到问题。我尝试将 Gridview 参数用于 header 字体样式,但它实际上不起作用。不幸的是,我尝试过的所有其他方法都不起作用。

  1. 使用 CSS Class
.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 header 设置为不加粗的最有效方法是什么?

更新(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>

试试下面的方法:

  th {
        font-weight: normal;
    }

您可以在 <asp:BoundField /> 上使用 HeaderStyle-Font-Bold 所以只需将其设置为 false,如下所示

HeaderStyle-Font-Bold="false"

添加一个 CssClass 即 "gvstyling" 到您的 gridview

像这样写一个css...

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

这是我添加到 Gridview 的 cssclass:

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

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