CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

How to select all dates of a Week and Month using Calendar control in ASP.Net ?
Submitted By Satheesh Babu B
On 8/5/2010 6:49:06 AM
Tags: ASP.Net,CodeDigest  

How to select all dates of a Week and Month using Calendar control in ASP.Net ?


By default, we will be able to select only one date from ASP.Net Calendar control. At times, we may have requirements where we need to provide users to select a continuous dates. For example, selecting all the dates in a week or all dates in a month.


The Calendar control has the flexibility to allow users to select all dates in a week and month by using SelectionMode property. By default, this property has value as "Day".


To select dates of entire week,


<asp:Calendar ID="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged" SelectionMode="DayWeek"></asp:Calendar>


To obtain the selected dates in codebehind,
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
foreach(DateTime dt in Calendar1.SelectedDates)
{
Response.Write(dt.ToString() +"<BR>");
}
}


To select dates of a entire month,
<asp:Calendar ID="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged" SelectionMode="DayWeekMonth"></asp:Calendar>

 

To obtain the selected dates in codebehind,
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
foreach(DateTime dt in Calendar1.SelectedDates)
{
Response.Write(dt.ToString() +"<BR>");
}
}

Happy Coding!!

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..