Let's say I have an aspx page with this calendar control:
<asp:Calendar ID="Calendar1" runat="server" SelectedDate="" ></asp:Calendar>
Is there anything I can put in for SelectedDate to make it use the current date by default, without having to use the code-behind?
TodaysDate = tomorrow; Calendar1. SelectedDate = Calendar1. TodaysDate; The following example shows how you can fill a DropDownList control with a selection of dates and then set the value of today's date in the Calendar control according to the user's selection from the list.
By default, the control displays the days of the month, day headings for the days of the week, a title with the month name and year, links for selecting individual days of the month, and links for moving to the next and previous month.
The calendar control is a functionally rich web control, which provides the following capabilities: Displaying one month at a time. Selecting a day, a week or a month. Selecting a range of days.
If you are already doing databinding:
<asp:Calendar ID="Calendar1" runat="server" SelectedDate="<%# DateTime.Today %>" />
Will do it. This does require that somewhere you are doing a Page.DataBind() call (or a databind call on a parent control). If you are not doing that and you absolutely do not want any codebehind on the page, then you'll have to create a usercontrol that contains a calendar control and sets its selecteddate.
DateTime.Now will not work, use DateTime.Today instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With