DatePicker Default Date Shown - c#

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);

Related

Date Picker Max value can't be selected after moving to previous date in C# Xamarin

I have this code to get a value of min date and max date I selected in datepicker. But right now, I am having a problem with max date. When I clicked the datepicker, the default value is TODAY. but when i switched it with previous date then go back to today's date, I can't select the date for today again. What's happening?
dialog.DatePicker.MinDate = (long)SpecificTransDate.ToUniversalTime()
.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds;
dialog.DatePicker.MaxDate = Java.Lang.JavaSystem.CurrentTimeMillis();

disable some date in date picker

hi i have a datepicker in my winforms and i want to disable the date exists in my dataBase?
num_reglement = date_paiement.Text + "-" + txtMatricule.Text;
paiement save_paiement = new paiement(num_reglement, double.Parse(txtmontantht.Text),
cmb_paiement.Text, txtbanque.Text, txt_cheque.Text,
date_paiement.Value.Date.ToShortDateString(), txtMatricule.Text, txtlibelle.Text);
save_paiement.insert();
I don't think date time Picker has any such property. It has Max-Date, Min-Date property if you have valid date range, if you want to validate from database ,Only way is to check in Text changed event if value exits in database and show popup of rejection.Otherwise use some third party Control.

how to enter day , month & year in dropdownlist from textbox in asp.net

I have a 3 dropdownlist for Day, Month & year . I am trying to put date from textbox to dropdownlist by breaking date into day , month and year.
Heres the code:
DDLDay.Text = Convert.ToDateTime(txtspousedob.Text).Day.ToString();
DDLMonth.Text =Convert.ToDateTime(txtspousedob.Text).Month.ToString();
DDLYear.Text = Convert.ToDateTime(txtspousedob.Text).Year.ToString();
Date that I have is "01/01/2002" but I am getting is
DDLDay gets "18"
DDLMonth gets "05"
DDLyear gets "2002"
So , what is the correct way to get the output
Thanks
You are probably left with the already selected text of drop down. First of all you need to ensure that the text you want to select. Then set the SelectedValue of the dropdown.
DDLDay.ClearSelection();
DDLDay.SelectedValue = DDLDay.Items.FindByText(txtspousedob.Text).Value;
Same applies to other DropDownLists

How to limit year in ajax calendar extender

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.

looking for a month/year selector control for .net winform

I am looking for a month selector control for a .net 2 winform.
Use DateTimePicker. You can use a custom format to enable just the month and year to be specified.
Example:
DateTimePicker dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM yyyy";
dateTimePicker1.ShowUpDown = true; // to prevent the calendar from being displayed
See this MSDN article for more information.
Edit:
To prevent the calendar from being displayed, set the ShowUpDown property on the DateTimePicker to true. This will prevent the calendar from being displayed and (in conjunction with a CustomFormat) allow you to set just the month and year by using the up/down buttons.

Categories