Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
2.17/5 (6 votes)
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
Updated 1-May-11 3:39am
v3

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
 
Share this answer
 
v2
Comments
Tarun.K.S 2-May-11 2:48am    
True. 5+
Sergey Alexandrovich Kryukov 2-May-11 4:02am    
Thank you, Tarun. Tiny thing, but there should be the order!
--SA
Espen Harlinn 4-May-11 18:37pm    
My 5
Sergey Alexandrovich Kryukov 4-May-11 21:37pm    
Thank you, Espen.
--SA
From your updated question it seems you need the namespace there too. Or put it in an using-declaration on top.

C#
e.Cell.BackColor = System.Drawing.Color.Red;
 
Share this answer
 
v2
Comments
Tarun.K.S 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+
Nish Nishant 1-May-11 9:56am    
Thanks Tarun!
Sergey Alexandrovich Kryukov 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 4-May-11 18:38pm    
Nice and simple, my 5
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.

:doh:
 
Share this answer
 
v2
Comments
#realJSOP 1-May-11 9:34am    
5 - proposed as answer
Tarun.K.S 1-May-11 9:53am    
Thanks!
Kim Togo 1-May-11 9:38am    
Good answer, my 5.
Tarun.K.S 1-May-11 9:53am    
Thanks!
Nish Nishant 1-May-11 9:56am    
My vote of 5!

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



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