I have a Calendar Extender.
I want to show only current year in calendar.
User can not select 2010 as current year is 2011.
So how to do this ?
Use the StartDate and EndDate properties to set a range of acceptable dates that you want to allow the user to select - you can set this in the markup as per krolik's answer, or in the code-behind so you can set it to the current year e.g.
CalendarExtender.StartDate = new DateTime(DateTime.Today.Year,1,1);
CalendarExtender.EndDate = new DateTime(DateTime.Today.Year,12,31);
Use StartDate property of your extender. For example:
<ajax:CalendarExtender ID="Calendar" StartDate="1/1/2011" runat="server" ... />
StartDate - Indicates start date for range that available for selection.
Related
Kendo's Angular Date Picker, restricts the date selection using [min] and [max] to select date from the UI. However, for text entry (user types in the date instead of selecting from the datepicker) user is restricted to enter months above 12 and dates above 30/31 accordingly. But, I need to restict user to type the year as well. Suppose if user types 1996 and my max year is 1995, the date year should change to 1995.
You can make one function which triggers when date is changed, this function should check if your requirements are satisfied with newly entered date OR it should revert back to last value . The Benefit of this approach is that user still can type the values but still it should be inside your validation range.
I have couple of datepicker implemented in Xaml .
- After user picks certain dates, a simple logic finds the earliest of the two dates. Also, it is not necessary for user to pick both dates.
I noticed that the "default" datepicker value if user does not pick any date is 1/1/0001.
Assuming the user picks the second date as 1/1/2017, the earliest of the two dates would always be 1/1/0001 which is not desired. In such scenario, the minimum date should be 1/1/2017.
what is the logic to neglect default date of 1/1/0001
There is a property MinYear which can be set to minimum year accepted which in your case obviously should be 2017. This will solve the problem by automatically limiting range of available values to be lower bounded by 2017-01-01 - this for UWP DatePicker.
In WPF DatePicker there is a DisplayDateStart property which can be set to minimum date available in drop down calendar which can be chosen by user. Similar property DisplayDateEnd is used for setting highest date which can be displayed in DatePicker. DatePicker.SelectedDateChanged is a very useful event which when wired up will capture changes to the dates on all instances of DatePickers and this can be used to create relations between them i.e. to enforce selection of the valid period which starts from date selected on DatePicker 1 and ends on date selected in DatePicker 2 by setting DisplayDateStart on picker 2 to date selected on picker 1 in event handler. This all together provides very high level of flexibility in controlling user input via DatePicker class.
I have a DatePicker and when I click into it to select a date, it's defaulted to show Today's Month. Is it possible to change the default month shown without setting the SelectedDate/SelectedValue? I have 2 DatePickers in my user control. I would like the second DatePicker to show 1 month after the first DatePicker.
Example
DatePicker1.SelectedDate = 2017-01-01
When clicking into DatePicker2, the defaulted showing month should be 2017-02-01
Set the DisplayDate property:
dp.SelectedDate = DateTime.Today;
dp.DisplayDate = DateTime.Today.AddMonths(1);
The question sounds illogical, but it is not:
I have 2 dates "Target" and "Actual". Usually the "Actual" date is very close to "Target", but not necessarily to the current date. To avoid the multiple clicks in the calendar that would navigate you to the month/year of interest, I set the selected date to my "Target" date when it is opened. This works great, BUT does not allow me to select that day, with the calendar closing automatically after selecting.
Any idea to solve this or any known alternative?
If you have a Calendar1 component, you can use a code like:
DateTime tomorrow = DateTime.Today.AddDays(1);
Calendar1.TodaysDate = tomorrow;
Calendar1.SelectedDate = Calendar1.TodaysDate;
When this calendar changed SelectionChanged the selected date, you can set the other calendar.
Tell me if you need more detail.
I have a date picker control that I use for a data collection application. It is using MvvM data binding. When going through a list of dates (see fig1) it will populate the date picker correctly. Whenever I hit new, the date pickers are nulled out. When I pull up the popup, it selects the month and year from the previous date that was set to. (fig 2) Is there anyway to default the pop up show the current month in the current year?
Note : I would like to keep the selected date to null on a new entry to force some validation.
Fig 1
Fig 2
The following image is to show what happens when I set the DisplayDateStart.
(original answer was horribly wrong, sorry about that)
Okay, lets try this again.
Have you tried setting the fallback to today's date?
SelectedDate="{Binding TehDate, FallbackValue={x:Static sys:DateTime.Now}}"