Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不使用CSS更改Gridview中的标题文本颜色_C#_Asp.net_Gridview - Fatal编程技术网

C# 不使用CSS更改Gridview中的标题文本颜色

C# 不使用CSS更改Gridview中的标题文本颜色,c#,asp.net,gridview,C#,Asp.net,Gridview,我正在使用asp.net c#。我正在使用gridview显示数据。我通过CSS控制所有的格式化。在gridview中,我定义了itemtemplate+edititemtemplate+footertemplate,并通过模板字段的bind列进行排序。我的问题是列名显示为标题,颜色没有通过CSS改变,字体大小,键入一切正常,但前颜色是固定的,因为蓝色是任何机构帮助我如何改变标题的前颜色,这是允许排序 我的代码如下所示: asp:TemplateField HeaderText=“Slsmn编号

我正在使用asp.net c#。我正在使用gridview显示数据。我通过CSS控制所有的格式化。在gridview中,我定义了itemtemplate+edititemtemplate+footertemplate,并通过模板字段的bind列进行排序。我的问题是列名显示为标题,颜色没有通过CSS改变,字体大小,键入一切正常,但前颜色是固定的,因为蓝色是任何机构帮助我如何改变标题的前颜色,这是允许排序

我的代码如下所示: asp:TemplateField HeaderText=“Slsmn编号”HeaderStyle CssClass=“GridHeaderStyle”SortExpression=“Profile\u Var”

问题是“Slsmn编号”。显示蓝色和下线,但在css中我给出了颜色:红色


谢谢

您指定的CSS类(GridHeaderStyle)将应用于标题单元格,而不是标题链接。听起来像是应用了默认链接颜色

将以下内容添加到CSS文件:

.GridHeaderStyle a {color: red;}
这将更改标题中的链接颜色


希望这有帮助

起初我尝试了杰里米的解决方案,但对我无效。这是因为生成的.asp代码在使其可排序时强制在标题中添加一个
标记

以下是解决问题的方法:

.GridHeaderStyle a {color: white!important}

这个!重要限定符将覆盖asp放入的样式。

发生这种情况是因为您尚未定义CSS规则来说明链接颜色

将以下内容添加到样式表中:

.GridHeaderStyle a {
    color: #f0f; /* or whatever */
}

这篇文章仍然没有最好的答案。我在同一个论坛上找到了下面的代码,ismailperim回答了这个问题

.GridStyle
{
    border: 6px solid rgb(217, 231, 255);
    background-color: White;
    font-family: arial;
    font-size: 12px;
    border-collapse: collapse;
    margin-bottom: 0px;
}
.GridStyle tr
{
    border: 1px solid rgb(217, 231, 255);
    color: Black;
    height: 25px;
}
/* Your grid header column style */
.GridStyle th
{
    background-color: rgb(217, 231, 255);
    border: none;
    text-align: left;
    font-weight: bold;
    font-size: 15px;
    padding: 4px;
    color:Black;
}
/* Your grid header link style */
.GridStyle tr th a,.GridStyle tr th a:visited
{
        color:Black;
}
.GridStyle tr th, .GridStyle tr td table tr td
{
    border: none;
}

.GridStyle td
{
    border-bottom: 1px solid rgb(217, 231, 255);
    padding: 2px;
}

它肯定会解决问题

任何解决方案都不起作用。我很简单地解决了这个问题。在网格定义的末尾添加了“HeaderStyle”属性。它看起来是什么样子:

... </Columns>
...
<HeaderStyle ForeColor="Red" />
<SelectedRowStyle ...
</asp:GridView> ...
。。。
...

如果您有选择,我将使用ListView控件。如果你想控制CSS和你已经在使用的模板字段,你能给我们看一下CSS代码吗