gpt4 book ai didi

c# - 在代码隐藏中将 CSS 添加到 GridView

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:08 25 4
gpt4 key购买 nike

我正在尝试设置我的 GridView 对象的样式,但我似乎无法让它使用 CSS 类。我正在动态创建 GridView,因此它们都是在代码隐藏中创建的。我尝试了以下方法,但似乎没有任何效果。

for (...)
{
GridView gv = new GridView();
gv.CssClass = "aclass";
gv.Attributes.Add("class", "aclass");
}

还有在 RowDataBound 事件中:

foreach (row in gv)
e.Row.Cells[i].CssClass = "aClass";

但我仍然无法设置我的数据样式。非常感谢任何建议

最佳答案

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].CssClass = "controlbackcolor";
e.Row.Cells[3].CssClass = "controlbackcolor";
}
}

这应该可以工作,但是您需要确保将 css 类放在正确的位置或进行链接。否则您将无法应用样式

您的 Css 类声明在 head 标记或链接中应类似于以下内容:

.controlbackcolor { 背景:绿色; 字体粗细:粗体; 白颜色; }

关于c# - 在代码隐藏中将 CSS 添加到 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15483636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com