Welcome to AspAdvice Sign in | Join | Help

Dynamic Data DateTime Formatting for Edits

While using the new ASP.NET Dynamic Data, I had a problem when a DateTime field from the database was displaying with the timestamp included.  I setup an attribute


on the field and it dropped the timestamp portion when it was in display mode, but when I switched to edit mode it was back...  It took quite a few combinations, but I found the proper syntax to use in the DateTime_Edit.ascx to get it to work properly (including when the data from the table is blank).  The specifier apparently needed to know it was actually a DateTime, but I ran into conversion issues when the column was empty so this did the trick!

<asp:TextBox ID="TextBox1" runat="server" CssClass="droplist" Text='<%# (FieldValueEditString != "") ? String.Format("{0:MM/dd/yyyy}",Convert.ToDateTime(FieldValueEditString)) : "" %>' Columns="20"></asp:TextBox>

Published Thursday, August 14, 2008 4:15 AM by robertb
Filed under:


# Dynamic Data DateTime Formatting for Edits

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Friday, August 15, 2008 8:30 AM by DotNetKicks.com
Anonymous comments are disabled