Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Calendar Control Date Methods

Author: DevASP Team

In this article I will explain you about the calendar control methods specifically for displaying date/day of selected date of calendar control.

To begin with this article drop two controls on your aspx page and these controls are label control and our main calendar control. When you drop calendar control two properties are by default set the “ID” and “runat”. Now what you have to do is set “SelectionMode=DayWeakMonth” and onSelectionChange event and you method which will fire when this event occurs. Finally your aspx code will be look like as follows:

 

<div>

 

 <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth"  OnSelectionChanged="my_date_change"  >asp:Calendar>

  <br /><br />

 

 <asp:Label ID="my_selected_date" runat="server">asp:Label>

 

div>   

And code for the method that will fire when event changed is as follows:

Sub my_date_change(ByVal sender As Object, ByVal args As System.EventArgs)

 

    Dim i As Integer

 

    For i = 0 To Calendar1.SelectedDates.Count - 1

        my_selected_date.Text = my_selected_date.Text & "
"
& Calendar1.SelectedDates(i).Date

    Next

 

End Sub

Above method will display the selected date in a way that it concatenates with the previously displayed date. Now if you want to display the selected day number of month the only change you need to do is set:  

 

Calendar1.SelectedDates(i).Day

 

Now if you want to read the day with respect to weak change the Day method with:

 

Calendar1.SelectedDates(i).DayOfWeek

 

Similarly you can display it with respect to year:

 

Calendar1.SelectedDates(i).DayOfYear

 

And finally if you want to display month number you can do so by using:

 

 Calendar1.SelectedDates(i).Month

 

Article Comments
I want a simple coding in visual basic in which i have to keep the record of days month year ,i mean when ever i click on March it gives me the record of all days that r saved in record and i want to see MARCH only written on status bar if anyone knows plzz help me

Posted on 4/21/2007 12:57:26 AM by maha

work 100 %
thxs very much!!!!!!!!!

Posted on 4/26/2007 11:50:23 AM by Ciper

Nice article!

Posted on 4/21/2008 1:50:09 PM by zeeshan

i learn a lot with it...

Posted on 12/22/2009 5:07:00 AM by vipul

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Implementing MARS using Visual Studio 2005

Disclaimer - Privacy
© 2002-2017 DevASP.net