网格视图单元格颜色变化

编程入门 行业动态 更新时间:2024-10-10 15:18:59
本文介绍了网格视图单元格颜色变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 我正在使用网格视图,其中数据如下图所示

Hi All I am using Grid view where data is coming like below

Rack 1 2 3 4 5 6 A1 20 40 A2 60 45 20 B1 34 30 20 10 C1 23 40

现在我的问题是如何使空白单元格绿色和填充单元格蓝色 感谢All

Now my question how can I make blank cell green colour and filled cell blue colour Thanks to All

推荐答案

我假设您正在使用ASP.Net C#. 为您的GridView创建GridView1_RowDataBound事件. I am assuming that you are using ASP.Net C#. Create GridView1_RowDataBound event for your GridView. if (e.Row.RowType = DataControlRowType.DataRow) { //Check your condition here If(Condition True) { e.Row.BackColor = Drawing.Color.Red // This will make row back color red } }

对于Windows应用程序:

For windows application:

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.Value != null) { if (e.Value.Equals(string.Empty)) e.CellStyle.BackColor = Color.Green; else e.CellStyle.BackColor = Color.Blue; } }

这称为Conditional Formatting.尝试下面的代码,希望它可以帮助您继续前进. 您可以在标记中启用RowDataBound事件 This is called Conditional Formatting. Try the code below hope it helps you move on. You can enable the RowDataBound Event in the markup <asp:gridview id="gridview1" runat="server" onrowdatabound="RowDataBound" xmlns:asp="#unknown"> </asp:gridview>

并将其放在您的 Code-Behind 文件中.

And put this in your Code-Behind file.

protected void RowDataBound(Object sender, GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { if(e.Row.RowIndex == 0) if(e.Row.Cells[0].Text == string.Empty) e.Row.Cells[0].BackColor = Color.Green; else e.Row.Cells[0].BackColor = Color.Blue; } }

更多推荐

网格视图单元格颜色变化

本文发布于:2023-11-23 04:16:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   视图   单元格   颜色

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!