Click Here to Download Sample MultipleDateSelectionInCalendarControl.zip
You can select multiple dates in calendar control.
There is a no direct way to select multiple dates in calendar control. You need to write some code for that.
Here is example for this.
In this example we take one calendar control and select multiple dates in that control and we display that selected dates in label.
ASPX Code :
C# Examples :
VB.net Examples :
Output :
You can select multiple dates in calendar control.
There is a no direct way to select multiple dates in calendar control. You need to write some code for that.
Here is example for this.
In this example we take one calendar control and select multiple dates in that control and we display that selected dates in label.
ASPX Code :
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" OnPreRender="Calendar1_PreRender" Width="330px" OnSelectionChanged="Calendar1_SelectionChanged" BorderStyle="Solid" CellSpacing="1"> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" /> <DayStyle BackColor="#CCCCCC" /> <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" /> <OtherMonthDayStyle ForeColor="#999999" /> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <TitleStyle BackColor="#333399" Font-Bold="True" Font-Size="12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" /> <TodayDayStyle BackColor="#999999" ForeColor="White" /> </asp:Calendar> <br /> <br /> <asp:Button runat="server" ID="btnGetSelectedDate" Text="Get Selected Date" onclick="btnGetSelectedDate_Click" /> <br /> <b>Selected Dates : </b><asp:Label runat="server" ID="lblDate" ></asp:Label>
C# Examples :
protected void Calendar1_PreRender(object sender, EventArgs e) { Calendar1.SelectedDates.Clear(); foreach (DateTime dt in MultipleSelectedDates) { Calendar1.SelectedDates.Add(dt); } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { if (MultipleSelectedDates.Contains(Calendar1.SelectedDate)) { MultipleSelectedDates.Remove(Calendar1.SelectedDate); } else { MultipleSelectedDates.Add(Calendar1.SelectedDate); } ViewState["MultipleSelectedDates"] = MultipleSelectedDates; } public List<DateTime> MultipleSelectedDates { get { if (ViewState["MultipleSelectedDates"] == null) ViewState["MultipleSelectedDates"] = new List<DateTime>() ; return (List<DateTime>)ViewState["MultipleSelectedDates"]; } set { ViewState["MultipleSelectedDates"] = value; } } protected void btnGetSelectedDate_Click(object sender, EventArgs e) { foreach (DateTime dt in MultipleSelectedDates) { lblDate.Text = lblDate.Text + " <br/> " + dt.ToString("dd/MM/yyyy"); } }
VB.net Examples :
Protected Sub Calendar1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Calendar1.SelectedDates.Clear() For Each dt As DateTime In MultipleSelectedDates Calendar1.SelectedDates.Add(dt) Next End Sub Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) If MultipleSelectedDates.Contains(Calendar1.SelectedDate) Then MultipleSelectedDates.Remove(Calendar1.SelectedDate) Else MultipleSelectedDates.Add(Calendar1.SelectedDate) End If ViewState("MultipleSelectedDates") = MultipleSelectedDates End Sub Public Property MultipleSelectedDates() As List(Of DateTime) Get If ViewState("MultipleSelectedDates") Is Nothing Then ViewState("MultipleSelectedDates") = New List(Of DateTime)() End If Return DirectCast(ViewState("MultipleSelectedDates"), List(Of DateTime)) End Get Set(ByVal value As List(Of DateTime)) ViewState("MultipleSelectedDates") = value End Set End Property Protected Sub btnGetSelectedDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetSelectedDate.Click For Each dt As DateTime In MultipleSelectedDates lblDate.Text = lblDate.Text + " <br/> " & dt.ToString("dd/MM/yyyy") Next End Sub
Output :
Note : Give
Us your valuable feedback in comments. Give your suggestions in this
article so we can update our articles accordingly that.
Good stuff.. nice and easy to read and use..
ReplyDeleteThanks :)
That is so GREAT! Nice way in so few codes to resolve many doubts!
ReplyDeleteDo you know what the best way to create the list as a comma separated label? Either way I concatenate I get either a leading or trailing comma.
ReplyDeletelblDate2.Text = lblDate2.Text + dt.ToString("dd/MM/yyyy") + " ,";
Dates selection of Calendar .NET control
ReplyDeletethanks bro.
ReplyDeleteThis code vb.net display double date
ReplyDeletesoo good! thanks
ReplyDeleteone day problem.one day select after select not deselected
ReplyDeleteI just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.
ReplyDeleteDot Net Training in Chennai
Hi, thanks for sharing such an informative blog. I have read your blog and I gathered some needful information from your blog. Keep update your blog. Awaiting for your next update.
ReplyDeleteweblogic tutorial
Thanks For Sharing Such an Important and Useful Content On Mulesoft Certification Training
ReplyDeleteReally Thanks for Posting Such an Useful Stuff...
ReplyDeleteJNTU 99
And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteDotnet Training in Chennai | NO.1 Dotnet Training in Chennai
Android Training in Chennai |NO.1 Best Android Training in Chennai
CCNA Training in Chennai | NO.1 CCNA Training in Chennai
MCSE Training in Chennai | NO.1 MCSE Training in Chennai
Embedded Systems Training in Chennai |NO.1 Embedded Systems Training in Chennai
Matlab Training in Chennai | NO.1 Matlab Training in Chennai
C C++ Training in Chennai | NO.1 C C++ Training in Chennai
Learn Digital Academy offers, Digital marketing training in bangalore
ReplyDeleteIt involves Training, Certification, Internships,and Placement.
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeletePython Training in Chennai| Best Python Training institute in Chennai
Datascience Training in Chennai |Best Datascience Training institute in Chennai
RPA Training in Chennai |Best RPA Training institute in Chennai
DevOps Training in Chennai |Best DevOps Training institute in Chennai
AWS Training in Chennai | Best AWS Training institute in Chennai
Azure Training in Chennai | Best Azure Training institute in Chennai
Salesforce Training in Chennai | Best Salesforce Training institute in Chennai
PowerBI Training in Chennai | Best PowerBI Training institute in Chennai
How can I write the dates but separeted by the month ex. 1,2,3 of July , 2,4,5 of August
ReplyDeleteThanks for sharing such an informative blog.Awaiting for your next update.
ReplyDeleteSelenium Training in chennai | Selenium Training in annanagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
Interesting blog thank you for sharing. Keep sharing.
ReplyDeleteBest software training institute in Chennai.
rpa course in chennai
DevOps Training in Chennai
Cloud-computing Training in Chennai
Ui-Path Training in Chennai
PHP Training in Chennai
Blue-Prsim Training in Chennai
Azure Training in Chennai
Existing without the answers to the difficulties you’ve sorted out
ReplyDeletethrough this guide is a critical case, as well as the kind which could
have badly affected my entire career if I had not discovered your
website.