gpt4 book ai didi

.net - 如何根据单元格的值更改 DataGridView 中行的背景色?

转载 作者:行者123 更新时间:2023-12-02 15:43:30 25 4
gpt4 key购买 nike

我有一个 DataGridView,它显示 DataTable 的内容。

我想根据该行中单元格的值设置该行的背景色。

请注意,相关单元格所在的列未显示在 DataGridView 中 (Visible=False)。

最佳答案

如果处理 RowDataBound 事件,您可以检查数据的值并修改单元格的属性或在该事件处理程序中应用不同的样式。

protected void Page_Load(object sender, EventArgs e)
{
GridView g1 = new GridView();
g1.RowDataBound += new GridViewRowEventHandler(g1_RowDataBound);
}

void g1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Check the Value
if(e.Row.Cells[1].Text = someValue)
{
e.Row.Cells[1].CssClass = "colorCellRed";
}

}
}

这应该会给你你正在寻找的东西。如果您需要 VB 而不是 C# 版本,请告诉我。

祝你好运!

关于.net - 如何根据单元格的值更改 DataGridView 中行的背景色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/190914/

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