Click here to Skip to main content
15,892,298 members

Need cell color change in gridview cell based on dates condition

Ubaid ur Rahman IT asked:

Open original thread
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


C#
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.
Tags: C#, ASP.NET, SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900