Click here to Skip to main content
11,645,087 members (66,203 online)
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 700
1 jyo.net 494
2 Sergey Alexandrovich Kryukov 449
3 Afzaal Ahmad Zeeshan 444
4 CPallini 426
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 703
2 Afzaal Ahmad Zeeshan 702
3 DamithSL 681
4 CPallini 595


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100