views:

20

answers:

1

Hi all,

I have a Gridview where I can modify the Time portion of a DateTime field. The update method is working well, except for one thing:

The field should only allow the time portion, e.g 08:23:09 but on the Database it saves it as a full DateTime, e.g 10/18/2010 08:23:09 AM. The problem is that upon editing, instead of adding the existing Date portion, it adds the current Date portion. So if I am editing the item from the last example into 08:25:09 instead of adding it as 10/18/2010 08:25:09 AM it adds it as 10/20/2010 08:25:09 AM which is obviously undesired behavior.

Here's how I am doing the update:

protected void grvOutHour_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       GridView grvOutHour = (GridView)this.grvReport.Rows[grvReport.EditIndex].FindControl("grvOutHour");
       TextBox txtBox = (TextBox) grvOutHour.Rows[e.RowIndex].FindControl("txtEditOutHour");
       string outHour = this.Source[grvReport.EditIndex].EntryDate + " " + txtBox.Text;
       odsOutHours.UpdateParameters["OutHour"].DefaultValue = outHour;
    }

Up to this point, outHour 's value is the desired one, e.g 10/18/2010 08:25:09 AM but as soon as the value is passed to my actual Update method:

public static void UpdateHour(int pEntryID, DateTime InHour, DateTime OutHour)
    {
         Hour hour = HoursDataMng.GetEntity(pEntryID, InHour.Date, InHour.TimeOfDay);
         if (hour == null)
             return;
         else
         {  
             hour.OutHour = OutHour;
             HoursDataMng.SubmitChanges();
         }
     }

I can see that OutHour has changed to 10/20/2010 08:25:09 AM

What's going on?

+1  A: 

Hi Eton:

Save the old Datetime in HiddenField then in the Update method get new value of the time and replace it in the old DateTime(From HiddenField) then pass the result to DB Parameter.

DEVMBM
Yes, I currently used something similar as a workaround, but I am wondering why the Date is being changed in the first place. Thanks though!
Eton B.