根据单元格值更改行的颜色 [英] Change color of row according to cell Value
本文介绍了根据单元格值更改行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我在我的页面中有这个
Hello. I have this in my page
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product Name"
SortExpression="ProductName" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="CriticalLevel" HeaderText="Critical Level"
SortExpression="CriticalLevel" />
</Columns>
</asp:GridView>
如果Quantity的值小于Red Level等等,我想更改Row的颜色.I试过这段代码
I want to change the color of the Row if the value of Quantity is less than Critical Level to Red etc etc. I tried this code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow pr = ((DataRowView)e.Row.DataItem).Row;
int id = Convert.ToInt32(pr["Quantity"]);
if(id==1)
e.Row.Cells[2].BorderColor = System.Drawing.Color.Red;
if(id < 1)
e.Row.Cells[2].BorderColor = System.Drawing.Color.Blue;
if(id==0)
e.Row.Cells[2].BorderColor = System.Drawing.Color.Violet;
}
}
我需要帮助。谢谢!!
I need help. Thank you!!
推荐答案
在行数据绑定函数中使用此代码
每行你可以指定背景颜色
Hi,
use this code in row data bound function
for each row you can assign background color
e.Row.BackColor = Drawing.Color.LightBlue
e.Row.ForeColor = Drawing.Color.Black
这篇关于根据单元格值更改行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文