【发布时间】:2015-06-13 01:44:34
【问题描述】:
我在强制 gridview 标题“取消粗体”时遇到问题。我尝试将 Gridview 参数用于标题字体样式,但它并没有真正起作用。不幸的是,我尝试过的所有其他方法都不起作用。
- 使用 CSS 类
.headercell
{
font-weight: normal;
font-size: 12px;
font-family: "Franklin Gothic Book"
}
-
以编程方式使用行数据绑定
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 像这样<asp:TemplateField HeaderText="Id" HeaderStyle-Font-Bold="false"> -
对于模板字段,我使用了该代码。但是,在自动生成的列上,我无法将标题 font.bold 设置为 false。
-
您需要设置
AutoGeneratedColumn = false。如果您的Header是固定的,则可以使用上述方法。向我们展示 Gridview aspx 的代码。以及您想要将字体粗体设置为 false 的位置。 -
不幸的是,我无法设置 AutoGeneratedColumn = false 因为 gridview 中的列是动态的(用户输入)。这就是我尝试使用 RowDataBound 以编程方式设置样式的原因。
-
能否展示gridview的aspx代码,以便我们更好地为您提供帮助
标签: css asp.net vb.net gridview header