网格视图单元格颜色变化 [英] Grid view cell colour change
本文介绍了网格视图单元格颜色变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在使用网格视图,其中数据如下图所示
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 calledConditional Formatting
. Try the code below hope it helps you move on.
You can enable theRowDataBound
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;
}
}
这篇关于网格视图单元格颜色变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文