Ivan Porto Carrero

Placeholder.Add("Really Cool Stuff");

  Home  |   Contact  |   Syndication    |   Login
  49 Posts | 6 Stories | 170 Comments | 81 Trackbacks

News

Article Categories

Archives

Post Categories

Personal Links

It seems that  because datetime is a value type it is impossible to save a null value.  If you use 2-way databinding in formview for saving dates. You will have problems even when just using a calendar control. This is the solution I found to my problem

In the html view change the Bind(”Date_Column”) into Eval(”Date_Column”)

<asp:TextBox ID="Timesheet_DateTextBox" runat="server" Text='<%# Bind("Timesheet_Date") %>' Width="124px"></asp:TextBox>

should then become

<asp:TextBox ID="Timesheet_DateTextBox" runat="server" Text='<%# Eval("Timesheet_Date") %>' Width="124px"></asp:TextBox>

I also want to store null values for unentered dates. A string you can null but this will give an exception like : System.String not a valid DateTime

i.e. for the objectdatasource inserting event i do it :

protected void odsTimesheet_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
     e.InputParameters[0] =
Guid.NewGuid();
     e.InputParameters[4] = SetDate("Timesheet_DateTextBox");
}

private object SetDate(string controlname)
{
     TextBox tb = (TextBox)fvProject.FindControl(controlname);
     return (tb.Text.Trim().Length == 0) ? (object)null : (object)DateTime.Parse(tb.Text);
}

If someone knows a better solution or a codeless one please let me know.

posted on Sunday, August 07, 2005 11:18 AM