The first example displays the currently selected day. The second example displays all selected dates, which might be a single day, a week, or a month.
Example
Visual BasicВ | Copy Code |
---|---|
' Example 1 Label1.Text = Calendar1.SelectedDate.ToShortDateString() ' Example 2 Dim s As String = "" Dim d As DateTime For Each d In Calendar1.SelectedDates s &= "<br />" & d.ToShortDateString() Next Label1.Text = s |
C#В | Copy Code |
---|---|
// Example 1 Label1.Text = Calendar1.SelectedDate.ToShortDateString(); // Example 2 String s = ""; foreach(DateTime d in Calendar1.SelectedDates) { s += "<br />" + d.ToShortDateString(); } Label1.Text = s; |
Compiling the Code
This example requires:
-
A Web Forms page.
-
A Calendar control named
Calendar1
. -
A Label control named
Label1
.
Robust Programming
If only one day is selected, the