Archive for August, 2005

07AugSaving null values to a DateTime field

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=’ Width=”124px”>FONT color=#800000>asp:TextBox>

should then become

<

asp:TextBox ID=”Timesheet_DateTextBox” runat=”server” Text=’ Width=”124px”>FONT color=#800000>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.

04AugCreating pdf in .NET without crystal reports

More in the article you can find here :

http://www.geekswithblogs.net/casualjim/articles/49098.aspx


Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler