Gridview中不同的行颜色 [英] Different row color in Gridview
本文介绍了Gridview中不同的行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
我正在从DB在Gridview中显示一组记录.
例如:姓名,地址,手机,ID
ID值为1或2.
如果ID为1,那么我希望完整的行以红色显示.
否则应显示为绿色.
如何在Gridview中实现此功能.
Dear Friends,
I am displaying a set of records in Gridview from DB.
Eg: Name, Address, Mobile, ID
ID value will be 1 or 2.
If ID is 1 then i want the complete row to be displayed in Red color.
else it should display in Green color.
How to implement this in Gridview.
Kindly guide.
推荐答案
尝试一下:
Try this:
foreach (GridViewRow gvrow in GridView1.Rows)
{
if(gvrow.Cells["ID"].Value = 1)
{
gvrow.DefaultCellStyle.BackColor = Color.Red;
}
else
{
gvrow.DefaultCellStyle.BackColor = Color.Green;
}
}
试试这个.
Hi,
Try this.
Private Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim id As Integer = CType(DataBinder.Eval(e.Row.DataItem, "ID"), Integer)
Select case ID
Case = "1"
e.row.BackColor=Drawing.Color.Green
Case Else
e.row.BackColor=Drawing.Color.Red
End Select
End If
End Sub
void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// cell[] postion of column having ID
if( e.Row.Cells[1].Text == "1")
{
e.Row.Style.Add("background","red");
}
else
{
e.Row.Style.Add("background","green");
}
}
}
这篇关于Gridview中不同的行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文