开发者

Gridview Update changing my update parameter?

I have a Gridview where I can modify the Time portion of a DateTime field. The update method is working well, exce开发者_如何学Gopt 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜