Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Hello Friends, Am working on Asp.net c#, SqlServer 2005.
 
In my SqlServer 2005 Database I have a table with two dates DateFrom and DateTo, for this both datates is used datatypes as nvarchar(10)....Because i need to display as 2013/01/16. its fine now
 
I need a Condition on this dates.....please help me.
 
I have Two Dates...., as DateFrom and DateTo
 
This data is displaying in Asp.net Gridview...In Gridview the DateFrom is Cell[4] and DateTo is Cell[5]....and now just i want to change the colors of cells based on date conditions.
 

DateFrom Date To
----------- ------------
2012/10/28 2013/03/30
2012/11/19 2013/03/21
2012/12/20 2013/03/26
2013/01/11 2013/01/12
 

If DateFrom <= todays date and datefrom >= todays date
{
item.cells[4].BackColor = color.FromName ("#77FF77");
item.cells[5].BackColor = color.FromName ("#77FF77");
}
 
else if DateFrom  < Todays date and dateto < todaysdate
{
item.cells[4].BackColor = color.FromName ("#FF6A6A");
item.cells[5].BackColor = color.FromName ("#FF6A6A");
}
else if datefrom >= todays date and dateto >= todaysdate
{
item.cells[4].BackColor = color.FromName ("#77FF77");
item.cells[5].BackColor = color.FromName ("#77FF77");
}
here #77FF77 indicates Green color
and #FF6A6A indicates red color.
 
Please help me, i need good else condition.
 
Thanks.
Posted 15-Jan-13 19:21pm
Edited 15-Jan-13 20:39pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

protected void grdA_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Decimal Val= GetCellValue(5, e);
            if (Val!= null)
            {
               if (Val< 0)
               {
                 ColorThisCellBackColor(5, e, Color.FromArgb(255, 235, 214));         }
            } 
        }
    }
 
private void ColorThisCellBackColor(int ColumnIndex, GridViewRowEventArgs e, Color ColorName)
   {
       e.Row.Cells[ColumnIndex].BackColor = ColorName;
   }
 
private Decimal GetCellValue(int ColumnIndex, GridViewRowEventArgs e)
 {
     try
     {
         Decimal cellval;
         if (HttpUtility.HtmlDecode(e.Row.Cells[ColumnIndex].Text).Trim() == string.Empty)
         {
             cellval = 0;
         }
         else
         {
             cellval = Convert.ToDecimal(HttpUtility.HtmlDecode(e.Row.Cells[ColumnIndex].Text).Trim());
         }
 
         return cellval;
 
     }
     catch (Exception)
     {
 
         throw;
     }
 
 }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 355
1 Maciej Los 180
2 Richard MacCutchan 115
3 arvind mepani 104
4 Tino Fourie 92


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid