在datagrid中如何让满足条件的行变为不一样的颜色???
------解决方案--------------------------------------------------------
private void ctlList_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.Item)
{
DataRowView drv=(DataRowView)e.Item.DataItem;
if(drv["WCSJ"].ToString()!="")
e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
}
}
------解决方案--------------------------------------------------------
以前我做的一个项目里面用到过类似的需求,仅供参考
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//customize the each row's color
switch (e.Row.Cells[0].Text.ToLower())
{
case "financial hold": e.Row.BackColor = Color.Pink;
break;
case "rejected": e.Row.BackColor = Color.Orange;
break;
case "submitted": e.Row.BackColor = Color.LightBlue;
break;
case "financial checking": e.Row.BackColor = Color.LightYellow;
break;
case "confirmed": e.Row.BackColor = Color.LightGreen;
break;
case "under shipping": e.Row.BackColor = Color.Purple;
break;
case "shipped": e.Row.BackColor = Color.Brown;
break;
case "goods received": e.Row.BackColor = Color.Chartreuse;
break;
case "closed": e.Row.BackColor = Color.SteelBlue;
break;
}
//change the color when mouse move in or out
e.Row.Attributes.Add("onmouseover", "curr=this.style.backgroundColor;cur2=this.style.color;
this.style.backgroundColor='#D1ECF3';this.style.color='black';");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=curr;this.style.color=cur2");
//change the type of the cursor
e.Row.Attributes.Add("style", "cursor:hand");
}
}