KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In the olden days before asp.net 4.5 we could easily bind a date to a Gridview, Formview or other databound control and make it look presentable with a simple format string. <asp:TextBox ID="DateFieldTextBox" runat="server" Text='<%# Bind("DateField","{0:d}") %>'/> The new, strongly typed model binding is a bit more difficult. <asp:TextBox ID="DateFieldTextBox" runat="server" Text='<%# BindItem.DateField %>'/> will work, but produces the full date/time string rather than just the date. <asp:TextBox ID="DateFieldTextBox" runat="server" Text='<%# BindItem.DateField.ToShortDateString() %>'/> .. this should work, but it produces a compile time error "Invalid code syntax for BindItem". Item.DateField.ToShortDateString() works but does not bind on the postback. For now we've reverted to the old syntax, but we would love to get the modern compile time checking but still be able to format the dates nicely. Anyone else ran into this before?
Tags (comma-separated)
Save Edits
Cancel