SharePoint - SPGrid how to show someitems in different background color

Asked By Bookworm on 11-Jan-12 08:31 AM

i need to do something like this:

if the date(which is field of grid) is > than "today" those items to be shown in another color for example Purple...

any idea for this?

Asked By Bookworm on 11-Jan-12 08:46 AM
Color.FromName("#FAF7DA"); this shows me error, what i have to add any reference for the Color????
Riley K replied to Bookworm on 11-Jan-12 08:56 AM

Is that based on some condition ??

apply css class

void gvSample_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
       if (int.Parse(e.Row.Cells[1].Text) < 10000)
          e.Row.Attributes.Add("class", "GridVIewRowStyle_RedColor");
       else if (int.Parse(e.Row.Cells[1].Text) > 10000 && int.Parse(e.Row.Cells[1].Text) < 20000)
           e.Row.Attributes.Add("class", "GridVIewRowStyle_YellowColor");
           e.Row.Attributes.Add("class", "GridVIewRowStyle_NoColor");

  border-right: #cccccc 0px solid;
  border-top: black 0px solid;
  padding-left: 8px;
  background-color: Red;
  text-decoration: none;
  border-width: 1px;
  border-color: black;

kalpana aparnathi replied to Bookworm on 11-Jan-12 02:48 PM
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    if (e.Row.DataItem != null)
      DataRowView drv = (DataRowView)e.Row.DataItem;
      string catName = Convert.ToString(drv["yourdate"]);
      if (catName.Trim() > Datetime.Today())
        e.Row.BackColor = System.Drawing.Color.Purple;