Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't have a valueless datepicker with the out-of-the-box control. Why? It is backed by DateTime, which is non-nullable.</p> <p>You can disable it with another control, or leave it disabled until the user clicks (bad UX for keyboard enthusiasts, like myself), or find or create (!) one that uses <code>Nullable&lt;DateTime&gt;</code>.</p> <h3>Edit:</h3> <p>In response to your comment, yes, you can do this; in fact, I've done it.</p> <ul> <li>use fields or private properties to hold the 'from' and 'to' dates, instead of reading them from the dtp, and set their defaults to min and max</li> <li>use a boolean flag to indicate when you are manipulating the dtp value in code, and in the dtp's <code>ValueChanged</code> event, set the flag's value to false</li> <li>in the form load event, set the flag to true and dtp value to today's date</li> <li>also in the <code>ValueChanged</code> event, set the <code>from</code> and <code>to</code> fields to the values of the dtps (you have to set both when either dtp changes, because the user will see the other one as set to today, but the search value will still be min or max).</li> </ul> <p>The problems with this is that once the user has changed the date selection, she can't easily go back to "all dates." Furthermore, the user can't select "today only" without first changing one of the dates and then changing it back.</p> <p>I think the best solution for you is to have a checkbox, "search by date range," which either enables the two dtps that are otherwise disabled, or displays the dtps that are otherwise hidden. Then you search from min to max unless the checkbox is checked, and when the checkbox <em>is</em> checked, you use the two dtp dates no matter what they are. Don't forget to deal with <code>to</code> and <code>from</code> being out of order, which can be done in several ways.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload