Displaying two months w Calendar conrol

D

Do

Hi:

How do I get two months to display side by side with my calendar control.
So when I move the month forward, both months are synchronisly monthed
forward.

For instance, I want to display Jan and Feb together in separate controls.
Then, when I click the arrow to move forward in months, it should then show
Feb and Mar.

Thanks,

Do
 
K

Ken Cox [Microsoft MVP]

Hi Do,

You can catch the SelectionChanged and VisibleMonthChanged events of each
calendar and then set the VisibleDate of each to one month ahead or back.

My working code is below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Calendar1.SelectedDate = Now.Today
Calendar2.VisibleDate = Now.Today.AddMonths(1)
End If
End Sub

Private Sub Calendar1_SelectionChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Calendar1.SelectionChanged
Calendar2.VisibleDate = _
Calendar1.VisibleDate.AddMonths(1)
End Sub

Private Sub Calendar2_SelectionChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Calendar2.SelectionChanged
Calendar1.VisibleDate = _
Calendar2.VisibleDate.AddMonths(-1)
End Sub

Private Sub Calendar1_VisibleMonthChanged _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) _
Handles Calendar1.VisibleMonthChanged
Calendar2.VisibleDate = _
Calendar1.VisibleDate.AddMonths(1)

End Sub

Private Sub Calendar2_VisibleMonthChanged _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) _
Handles Calendar2.VisibleMonthChanged
Dim dt As DateTime
Calendar1.VisibleDate = _
Calendar2.VisibleDate.AddMonths(-1)
End Sub


<form id="Form1" method="post" runat="server">
<P>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" border="1">
<TR>
<TD>
<asp:Calendar id="Calendar1" runat="server"></asp:Calendar></TD>
<TD>
<asp:Calendar id="Calendar2" runat="server"></asp:Calendar></TD>
</TR>
</TABLE>
</P>
<P>&nbsp;</P>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top