我正在使用asp.net c#。我正在使用gridview来显示数据。我通过CSS控制所有格式化。在gridview中,我定义了itemtemplate + edititemtemplate + footertemplate,并在模板字段中通过bind列进行排序。我的问题是作为标题的列名称,颜色没有通过CSS改变,字体大小,类型所有的东西都可以,但前面的颜色是固定的,因为蓝色是任何身体帮助我如何改变标题的前景,这是允许的排序
我的代码如下: asp:TemplateField HeaderText =“Slsmn No.” HeaderStyle-CssClass =“GridHeaderStyle”SortExpression =“Profile_Var”
问题是“Slsmn No.”显示蓝色和下划线,但在css我给了颜色:红色
由于
答案 0 :(得分:3)
您分配的CSS类(GridHeaderStyle)正在应用于标题单元格,而不是标题链接。这听起来像是应用了默认的链接颜色。
将以下内容添加到CSS文件中:
.GridHeaderStyle a {color: red;}
这应该改变标题中的链接颜色。
希望这有帮助!
答案 1 :(得分:1)
起初我尝试过Jeremy的解决方案,但它对我不起作用。这是因为当您对其进行排序时,生成的.asp代码会在标题中强制使用<style="color: #333333">
标记。
以下是解决问题的方法:
.GridHeaderStyle a {color: white!important}
!important限定符将覆盖asp放入的样式。
答案 2 :(得分:0)
这是因为你没有定义一个CSS规则来说明链接颜色。
将以下内容添加到样式表中:
.GridHeaderStyle a {
color: #f0f; /* or whatever */
}
答案 3 :(得分:0)
这篇文章仍然没有最佳答案。我在同一个论坛中找到了以下代码,由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;
}
它肯定会解决问题
答案 4 :(得分:0)
不适用于任何解决方案。我很简单地解决了这个问题。在网格定义的末尾添加了“ HeaderStyle”属性。看起来如何:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <sstream>
#include <numeric>
// Unfortunately the std::reference_wrapper does not work as expected.
// So we will build our own one
class IntRef
{
// Here we will store the reference
std::tuple<int&> t;
public:
// Constructor. Take reference and store it in tuple
IntRef(int&& intV) : t(intV) {}
// Assignment to the referenced value
int operator =(const int i) { std::get<0>(t) = i; return i; }
// Explicit type cast to int&
operator int& () { return std::get<0>(t); }
// And, return the reference
decltype(&std::get<0>(t)) operator&() { return &std::get<0>(t); }
};
// Some definitions to make reading easier
using IntRefV = std::vector<IntRef>;
using MatrixCIterator = std::vector<IntRef>::iterator;
using Columns = std::vector<int>;
using MatrixRIterator = Columns::iterator;
// The matrix
class Matrix
{
public:
// Constructor defines the matrix size
Matrix(size_t numberOfRows, size_t numberOfColumns);
// Iterators for rows are simple, becuase we have vectors of columns. Use unterlying iterator
MatrixRIterator rowIterBegin(size_t row) { return data[row].begin(); }
MatrixRIterator rowIterEnd(size_t row) { return data[row].end(); }
// Column iterator is complicated. Retzurn iterator to vevtor of references to column values
MatrixCIterator columnIterBegin(size_t column) { return columnReferences[column].begin(); }
MatrixCIterator columnIterEnd(size_t column) { return columnReferences[column].end(); }
// Access data of matrix
std::vector<int>& operator [] (const size_t row) { return data[row]; }
// And, for debug purposes. Output all data
friend std::ostream& operator << (std::ostream& os, const Matrix& m) {
std::for_each(m.data.begin(), m.data.end(), [&os](const Columns & columns) {std::copy(columns.begin(), columns.end(), std::ostream_iterator<int>(os, " ")); std::cout << '\n'; });
return os;
}
protected:
//The matrix, vector of vector of int
std::vector<Columns> data;
// The references to columns in data
std::vector<IntRefV> columnReferences{};
};
// Constructor. Build basic matrix and then store references to columns in data
Matrix::Matrix(size_t numberOfRows, size_t numberOfColumns) : data(numberOfRows, std::vector<int>(numberOfColumns)), columnReferences(numberOfColumns)
{
for (size_t column = 0; column < numberOfColumns; ++column)
for (size_t row = 0; row < numberOfRows; ++row)
columnReferences[column].emplace_back(IntRef(std::move(data[row][column]))); // Std::move creates a rvalue reference (needed for constructor, nothing will be moved)
}
// Some test data for the istream_iterator
std::istringstream testData("1 2 10");
// Test the matrix
int main()
{
// Define a matrix with 3 rows and 4 columns
Matrix matrix(3, 4);
// Test 1: Fill all values in column 2 with 42
for (MatrixCIterator ci = matrix.columnIterBegin(2); ci != matrix.columnIterEnd(2); ++ci) {
*ci = 42;
}
std::cout << matrix << "Column 2 filled with 42\n\n";
// Test 2: Read input from istream and copy put that in column 1
std::copy_n(std::istream_iterator<int>(testData), 3, matrix.columnIterBegin(1));
std::cout << matrix << "Column 1 filled with testData '" << testData.str() << "'\n\n";
// Test 3: Copy column 2 to cout (Print column 2)
std::copy(matrix.columnIterBegin(2), matrix.columnIterEnd(2), std::ostream_iterator<int>(std::cout, " "));
std::cout << "This is column 2\n\n";
// Test 4: Sum up the first 2 values of column 1 and show result
std::cout << "\nSum of first 2 values of column 1: " << std::accumulate(matrix.columnIterBegin(1), matrix.columnIterBegin(1) + 2, 0) << "\n\n";
// Test 5: Fill all values in row 0 with 33
std::for_each(matrix.rowIterBegin(0), matrix.rowIterEnd(0), [](int& i) { i = 33; });
std::cout << matrix << "Row 0 filled with 33\n\n";
return 0;
}