.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Calendar Control Configurations for ASP.NET

Posted By:Hefin Dsouza       Posted Date: August 27, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  
 

Calendar Control Configurations for ASP.NET. The Day_Render Event of the Calendar Control can be used for many purposes like Enabling and Disabling Valid Dates.

A) To Only allow users to select dates less than today's date you can use the Following code.


Note That the Code has to be written on the DayRender event of the Calendar Control


protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date >= DateTime.Today.Date)
{
e.Cell.Enabled= false; // Changes the Cells Enable Property
e.Day.IsSelectable = false; // Disables the Cells Click Property
}
}

B) To Only allow users to select dates greater than today's date you can use the Following Code



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date <= DateTime.Today.Date)
{
e.Cell.Enabled= false; // Changes the Cells Enable Property
e.Day.IsSelectable = false; // Disables the Cells Click Property
}
}

C) To format Specific Dates with special formating features and Disabling the Clicks on it



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date == DateTime.Today.AddDays(-3))//Code for Specific Date
{
e.Cell.ForeColor = System.Drawing.Color.Red;
e.Cell.ToolTip = "Holiday "; // ToolTip for the Date
e.Day.IsSelectable = false;
}
if (e.Day.Date == DateTime.Today.AddDays(-7))//Code for Specific Date
{
e.Cell.ForeColor = System.Drawing.Color.Red;
e.Cell.ToolTip = "Holiday "; // ToolTip for the Date
e.Day.IsSelectable = false;
}
}

D) To Higlight all WeekEnds



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsWeekend)
{
e.Cell.ForeColor = System.Drawing.Color.Red;
}
}

Hope This is Usefull
Regards
Hefin Dsouza

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend