开发者

ASP.NET How to add datetime as default value to data source details view?

I want to add the current date tim开发者_StackOverflowe as default value in the following field as default value.

I tired the following

<asp:Parameter Name="AddedDate" Type="DateTime" DefaultValue="<% DateTime.Now.ToString() %>"/>

and

<asp:Parameter Name="AddedDate" Type="DateTime" DefaultValue="<% Response.Write(DateTime.Now.ToString()) %>"/>

But got error: String was not recognized as a valid DateTime.

How do i fix it? and is there any better approach?

Thanks.


You can't add a Default the way you are doing, but you can pass the DateTime.Now as parameter in the DetailsView Inserting/Updating event. e.g.

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
  e.Values["AddedDate"] = DateTime.Now;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜