Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
protected void CalendarDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
    {
        // If the month is CurrentMonth
        if (!e.Day.IsOtherMonth)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))
                {
                    DateTime dtEvent = (DateTime)dr["EventDate"];
                    if (dtEvent.Equals(e.Day.Date))
                    {
                        e.Cell.BackColor=Colors.Red;//Colors does not exist in the current context i develop calender and on which date i set event color of that date change
                    }
                }
            }
        }
        //If the month is not CurrentMonth then hide the Dates
        else
        {
            e.Cell.Text = "";
        }
    }
Posted 1-May-11 3:56am
om560
Edited 1-May-11 4:39am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Do it like this:
Add this using namespace:
 
using System.Drawing;
 
e.Cell.BackColor = Color.Red

 
Update : A small correction, use Color itself, just add the using.
 
D'Oh! | :doh:
  Permalink  
v2
Comments
   
5 - proposed as answer
Tarun.K.S at 1-May-11 9:53am
   
Thanks!
Kim Togo at 1-May-11 9:38am
   
Good answer, my 5.
Tarun.K.S at 1-May-11 9:53am
   
Thanks!
Nishant Sivakumar at 1-May-11 9:56am
   
My vote of 5!
Tarun.K.S at 1-May-11 9:59am
   
You forgot to vote! :D
Nishant Sivakumar at 1-May-11 10:00am
   
Sorry. Corrected! Check again.
Tarun.K.S at 1-May-11 10:02am
   
Aah thanks a lot, love that green color! :D
Nishant Sivakumar at 1-May-11 10:03am
   
:-)
Prasanta_Prince at 1-May-11 11:11am
   
Good one.
Tarun.K.S at 1-May-11 12:56pm
   
Thanks!
SAKryukov at 1-May-11 18:31pm
   
Tarun, add semicolon after the statement. Other that that, it's OK. My 5.
--SA
Tarun.K.S at 2-May-11 2:47am
   
Oops forgot, thanks for the 5.
SAKryukov at 2-May-11 4:01am
   
Not added so far. After "Color.Red" + ";".
--SA
SAKryukov at 1-May-11 18:33pm
   
Also, it can be missing reference, not just "using".
 
So, please see my answer.
--SA
Tarun.K.S at 2-May-11 2:48am
   
Hmm true, anyway I just created a new We application and found that it's already referenced. But good point.
Espen Harlinn at 4-May-11 18:38pm
   
5ed!
Tarun.K.S at 5-May-11 2:06am
   
Thank you Espen! :D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

From your updated question it seems you need the namespace there too. Or put it in an using-declaration on top.
 
e.Cell.BackColor = System.Drawing.Color.Red;
  Permalink  
v2
Comments
Tarun.K.S at 1-May-11 9:54am
   
Hi Nish, I just checked and found that its Color itself, OP has to add that using namespace too. I have modified your solution for the same.
5+
Nishant Sivakumar at 1-May-11 9:56am
   
Thanks Tarun!
SAKryukov at 1-May-11 18:34pm
   
Correct, my 5, but it the assembly reference could be missing -- one more point.
Please see my answer.
--SA
Espen Harlinn at 4-May-11 18:38pm
   
Nice and simple, my 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check up if the assembly System.Drawing is referenced by the project.
 
A side note: don't use immediate constants like "". It should be string.Empty.
 
—SA
  Permalink  
v2
Comments
Tarun.K.S at 2-May-11 2:48am
   
True. 5+
SAKryukov at 2-May-11 4:02am
   
Thank you, Tarun. Tiny thing, but there should be the order!
--SA
Espen Harlinn at 4-May-11 18:37pm
   
My 5
SAKryukov at 4-May-11 21:37pm
   
Thank you, Espen.
--SA

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 Andreas Gieriet 100
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 May 2011
Copyright © CodeProject, 1999-2014
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