PDA

View Full Version : [CLOSED] DateField : EmptyValue



matrixwebtech
Jan 05, 2015, 3:08 PM
Hi I setup a datefield like bellow


<ext:DateField runat="server" ID="dtTodate" FieldLabel="To" AllowBlank="true" Editable="false" SelectOnFocus="true" LabelAlign="Left" Format="dd-MM-yyyy" >
</ext:DateField>

And try to get this value on buttonclick

dtFromdate.Value.ToString()
or

dtFromdate.Text.ToString()

its return 1/1/0001 12:00:00 AM in case of field is empty. how I set this field if empty then value is NULL in code behind.is it possible?

Dimitris
Jan 05, 2015, 3:40 PM
I suggest you use the SelectedDate property.

You can check again the DateTime.MinValue.

matrixwebtech
Jan 06, 2015, 10:55 AM
Hi,
is it possible to set selected date to datefield like bellow?

<ext:DateField runat="server" ID="dt" SelectedDate="<%= System.DateTime.Now.ToString() %>" Format="dd-MMM-yyyy"></ext:DateField>

Daniil
Jan 06, 2015, 11:28 AM
Yes, it is possible to do.

<ext:DateField
runat="server"
SelectedDate="<%# System.DateTime.Now %>"
Format="dd-MMM-yyyy"
AutoDataBind="true" />

matrixwebtech
Jan 06, 2015, 11:41 AM
Thank you once again .one more thing


string s = DateField1.Text;
in s variable I get 1/6/2015 12:00:00 AM my question is ,is it possible to terminate the time part from control setting? and is it possible to format the date also?

Dimitris
Jan 06, 2015, 12:28 PM
IMHO, what you are missing is the fact that the SelectedDate property is a DateTime not a string (contrary to the Text property, which I do not think is the right way to go with the DateField). So, once you've got the SelectedDate you can do anything you would normally do with a DateTime object in C#, for example:



string datePartOnly = DateField1.SelectedDate.Date.ToString("dd/MM/yyyy");


etc...