E-Bat
E-Bat

Reputation: 4892

Date format in strong typed ListView's EditItemTemplate

This is my markup for EditItemTemplate section of a ListView, i want to render short dates format:

<asp:TextBox ID="txtFechaArribo" runat="server" Text='<%# string.Format("{0:dd/MM/yyyy}", BindItem.FechaArribo ) %>'>

Which produce the runtime exception :

BindItem does not exist in the current context

Without format expression it works but with the not desired time component. Advices?

Upvotes: 1

Views: 536

Answers (2)

EsseyG
EsseyG

Reputation: 46

At last after struggling for two days I get a solution for this two way model binding issue for formatted field value. Just remove the "" or '' after the property text of the TextBox. It works for me like a charm!! But if you use the TextMode property of the TextBox to Date, remove it. Cause, it will not display a value from server or DB. If you want to use a datepicker or calendar, you can simple add an AJAX CalendarExtender control to pick a date from calendar.

<asp:TextBox ID="txtFechaArribo" runat="server" Text=<%# Bind("FechaArribo", "{0:dd/MM/yyyy}") %>/>

Upvotes: 1

Smeegs
Smeegs

Reputation: 9224

You can use Bind("FechaArribo","{0:d}"), although it will technically be a breach of strong-typing.

Upvotes: 1

Related Questions