Set DateTimePicker value to be null

前端 未结 8 1072
感情败类
感情败类 2020-12-01 16:43

I am developing a WinForms UI with two DateTimePicker controls. Initially I want to set the value of the controls to null until a user selects a date. If the us

相关标签:
8条回答
  • 2020-12-01 17:35

    Let suppose dtpStartDate is your DateTimePicker control.

    Write this code in Page_Load-

    `dtpStartDate.Format = DateTimePickerFormat.Custom;
                dtpStartDate.CustomFormat = " ";`
    

    Write this code in Value_Changed event-

    `startDate = Convert.ToString(dtpStartDate.Value);
            dtpStartDate.Format = DateTimePickerFormat.Short;`
    

    here selected 'short' as Format. You can select 'Long' and other option available.

    0 讨论(0)
  • 2020-12-01 17:35

    May be you need to create a UserControl withe the Appereance of a TextBox,and when the user click on a Calender Show, when you select a Date set it to the TextBox. It will allow nulls values.

    The DateTimePicker does not allow null.

    0 讨论(0)
提交回复
热议问题