How To: Customize Calendar Control to limit the users to select day on or after today

In this Sample code we will see how to customize calendar control to limit the user to select the day on or after today

Step 1: Drag Drop Calendar Control

<asp:Calendar id="Calendar1"  runat="server"></asp:Calendar>

Step 2: In code behind use the below code in DayRender Event

The DayRenderEventArgs object contains two properties that you can use to programmatically control the format of the date cell. The Cell property represents the cell being rendered, while the Day property represents the date to render in the cell.

Set the Day's IsSelectable property to true or false depending on the criteria. In this code sample we will limit user to select day on or after today.

VB.NET Code

Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

e.Day.IsSelectable = e.Day.Date >= DateTime.Now

End Sub

C# Code

void OnDayRender (Object sender, DayRenderEventArgs e)

{

e.Day.IsSelectable = e.Day.Date >= DateTime.Now;

}

Published Sunday, January 22, 2006 6:32 PM by SushilaSB
Filed under:

Comments

Monday, January 23, 2006 3:42 AM by dion

# re: How To: Customize Calendar Control to limit the users to select day on or after today

Simple and effective!
Thursday, July 26, 2007 3:20 PM by firoz

# re: How To: Customize Calendar Control to limit the users to select day on or after today

Hi,

I want an asp.net calendar that acts very much like the one at http://www.onestat.com The calendar should be in Asp.net in VB only with clear comments.

Please see pictures for more detail. Feel free to ask any questions.

Instruction on how login to onestat.com

step1.jpg

step2.jpg

My needs on this project

instruction.jpg

thanks

Leave a Comment

(required) 
(required) 
(optional)
(required)