开发者

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

开发者 https://www.devze.com 2023-03-17 05:20 出处:网络
I want to add the current date tim开发者_StackOverflowe as default value in the following field as default value.

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

精彩评论

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