C# 不通过使用 CSS 更改 Gridview 中的标题文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/655947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Not Changing Header Text Color In Gridview through using CSS
提问by Kartik
I am using asp.net c#. I am using gridview to display the data. i am controlling all formating through CSS. In gridview i have define itemtemplate + edititemtemplate + footertemplate and doing sorting through bind column at template field. My problem is the column name which dispalay as header that color is not changed through CSS, font size,type all things going ok but fore color is fix as Blue is any body help me out how can i change forecolor of header which is allow to sorting.
我正在使用 asp.net c#。我正在使用 gridview 来显示数据。我正在通过 CSS 控制所有格式。在 gridview 中,我定义了 itemtemplate + edititemtemplate + footertemplate 并通过模板字段的绑定列进行排序。我的问题是列名称显示为标题,颜色不会通过 CSS、字体大小、输入一切正常,但前景色是固定的,因为蓝色是任何主体,请帮助我如何更改标题的前景色,这是允许的排序。
My code looks like : asp:TemplateField HeaderText="Slsmn No." HeaderStyle-CssClass="GridHeaderStyle" SortExpression="Profile_Var"
我的代码看起来像:asp:TemplateField HeaderText="Slsmn No." HeaderStyle-CssClass="GridHeaderStyle" SortExpression="Profile_Var"
Problem is "Slsmn No." Display blue color and under line but in css i gave color:red
问题是“Slsmn 号” 显示蓝色和下划线,但在 css 中我给了 color:red
Thanks
谢谢
回答by Jeremy
The CSS class you've assigned (GridHeaderStyle) is being applied to the header cells, not the header links. It sounds like the default link color is being applied.
您分配的 CSS 类 (GridHeaderStyle) 将应用于标题单元格,而不是标题链接。听起来像是应用了默认链接颜色。
Add the following to your CSS file:
将以下内容添加到您的 CSS 文件中:
.GridHeaderStyle a {color: red;}
This should change the link color in the headers.
这应该会更改标题中的链接颜色。
Hope this helps!
希望这可以帮助!
回答by Jeremy
At first I tried Jeremy's solution, but it didn't work for me. This is because the .asp code generated forces a <style="color: #333333">
tag in the header when you make it sortable.
起初我尝试了 Jeremy 的解决方案,但它对我不起作用。这是因为<style="color: #333333">
当您使其可排序时,生成的 .asp 代码会强制在标头中添加一个标记。
Here's how to solve the problem:
以下是解决问题的方法:
.GridHeaderStyle a {color: white!important}
The !important qualifier will override the style that asp puts in.
!important 限定符将覆盖 asp 放入的样式。
回答by Deniz Dogan
This happens because you have not defined a CSS rule which says anything about the link color.
发生这种情况是因为您还没有定义任何关于链接颜色的 CSS 规则。
Add the following to your stylesheet:
将以下内容添加到您的样式表中:
.GridHeaderStyle a {
color: #f0f; /* or whatever */
}
回答by U.Y.
This post still doesn't have a best answer. I found below code in the same forum which is answered by ismailperim.
这篇文章仍然没有最佳答案。我在同一个论坛中找到了下面的代码,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;
}
It will solve the problem for sure
它肯定会解决问题
回答by Tomas Vileikis
Not worked ANY of solutions. I solved this problem very simply. Added "HeaderStyle" attribute in the end of grid definition. How it looks like :
没有任何解决方案。我很简单地解决了这个问题。在网格定义的末尾添加了“HeaderStyle”属性。它的样子:
... </Columns>
...
<HeaderStyle ForeColor="Red" />
<SelectedRowStyle ...
</asp:GridView> ...