我有一个网格视图,可以在其中修改日期时间字段的时间部分。更新方法工作得很好,除了一件事:
字段应只允许时间部分,例如
08:23:09
但在数据库中,它将其保存为完整的日期时间,例如
10/18/2010 08:23:09 AM
. 问题是,在编辑时,它不添加现有的日期部分,而是添加当前的日期部分。因此,如果我将上一个示例中的项编辑为
08:25:09
而不是将其添加为
10/18/2010 08:25:09 AM
它把它当作
10/20/2010 08:25:09 AM
这显然是不受欢迎的行为。
以下是我的更新方式:
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;
}
到目前为止,
outHour
的值是所需的值,例如
2010年10月18日上午08:25:09
但一旦该值传递给我的实际更新方法:
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();
}
}
我可以看到外面的时间变了
2010年10月20日上午08:25:09
发生什么事?