Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add next/previous year button to asp calendar control

Need to add a button for next previous year in ASP calendar control dynamically.

How can I add it right next to the existing next and prev controls? Is it possible to do this via dayrender event ?? Please help

like image 874
Rahul Avatar asked Jan 17 '13 13:01

Rahul


People also ask

Which control is used to select date in ASP net?

The ASP.NET Web Forms DateTime Picker control is used to enter or select date and time values from a pop-up calendar and dropdown time list. It provides month, year, and decade views for quick navigation to the desired date.


1 Answers

Try the below...

<asp:Calendar ID="calender1" runat="server" VisibleDate="2012-10-10"></asp:Calendar>
<asp:Button ID="btnMNext" runat="server" Text="Next Month" />
<asp:Button ID="btnMPrev" runat="server" Text="Prev Month" />
<asp:Button ID="btnNextYr" runat="Server" Text="Next Year" />
<asp:Button ID="btnPrevYr" runat="server" Text="Prev Year" />
<br />
<asp:TextBox ID="txtcur" runat="server"></asp:TextBox>

in code behind

**btnMNext_Click**
String month;
month = calender1.SelectMonthText();
txtcur.Text = calender1.SelectedDate.ToShortDateString();
calender1.VisibleDate = calender1.VisibleDate.AddMonths(1);

**btnPrevYr_Click**
    calender1.VisibleDate = calender1.VisibleDate.AddYears(-1);


**btnNextYr_Click**
    calender1.VisibleDate = calender1.VisibleDate.AddYears(1);
End Sub

**btnMPrev_Click**
    calender1.VisibleDate = calender1.VisibleDate.AddMonths(-1);
like image 50
Pandian Avatar answered Sep 21 '22 14:09

Pandian