Quantcast
Channel: ppedv Team Blog
Viewing all articles
Browse latest Browse all 1198

ASP.NET Modelbinding Formatting BindItem

$
0
0

Modelbinding ist eine feine Sache. Mit typisierten Daten und Intellisense-Unterstützung können Formulare erstellt werden. Für eine einfache Bindung wird das Schlüsselwort Bind verwendet.

In diesem Beispiel ist eine Klasse mit einem Property vom Typ Datum an ein Formview Control gebunden.

   1:  <ItemTemplate>
   2:  <label>Id:</label><%#Item.id%><br/>
   3:  <label>Name:</label><%#Item.name%><br/>
   4:  <label>Geburtsdatum:</label><%#Item.geburtstag.ToShortDateString%><br/>
   5:  <asp:Buttonrunat="server"ID="UpdateButton"CommandName="Edit"Text="Edit"/>
   6:  </ItemTemplate>

Wenn man das Datum ohne Formatierung ausgibt, erhält man eine Anzeige wie 12.10.1955 00:00:00.  Also wird hier mit toShortDateString formatiert. Im Edit-Modus ist das etwas komplizierter bzw. erzeugt einen Laufzeit-Fehler, obwohl laut Intellisense und Compiler die Methode zur Verfügung steht.

DataBinding: System.DateTime enthält keine Eigenschaft mit dem Namen ToShortDateString.

Der einzig gefundene Workaround ist die bisherige Methode über Bind() zu verwenden.

   1:  <EditItemTemplate>
   2:  <label>Id:</label><%#Item.id%><br/>
   3:  <label>Name:</label><asp:TextBoxrunat="server"ID="name1"required
Text="<%#BindItem.name%>"></asp:TextBox><br/>
   4:  <label>Geburtsdatum:</label><asp:TextBoxrunat="server"ID="TextBox1"
   5:  Text='<%#Bind("geburtstag", "{0:yyyy/MM/dd}") %>'></asp:TextBox><br/>
   6:  <asp:Buttonrunat="server"ID="SaveButton"CommandName="Update"Text="Save"/>
   7:  <asp:Buttonrunat="server"ID="CancelButton"CommandName="Cancel"Text="Cancel"/>
   8:  </EditItemTemplate>

Viewing all articles
Browse latest Browse all 1198

Trending Articles


Love Quotes Tagalog


FORTUITOUS EVENT


Pokemon para colorear


Girasoles para colorear


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo Create - Video Maker & Editor 1.5.2 by Vimeo Inc


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Pocoyo para colorear


Sapos para colorear


Patama lines and Tagalog Quotes Pinoy Sayings


“BAHAY KUBO HUGOT”


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 11.6.0 by Vimeo.com, Inc.