SharePoint - SPGrid how to show someitems in different background color

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

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?

thnx
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");
       else
           e.Row.Attributes.Add("class", "GridVIewRowStyle_NoColor");
      }
    }
}

.GridVIewRowStyle_RedColor
{
  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;
}


Regards
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;
    }
  }