c# - ASP.NET data binding multiple format -


i have asp.net 4.5 web forms site using ef 5.

one of object of data model 'medical file' datetime property (among others):

public partial class medfile {     public system.guid medfileid { get; set; }     public string name { get; set; }     public nullable<system.datetime> meddate { get; set; }     ... } 

here snippet of web form editing:

<asp:listview id="medfilesform" runat="server"      itemtype="medfile" datakeynames="medfileid"      selectmethod="getfiles"     updatemethod="updatefile">     ...     <edititemtemplate>         <asp:label id="label1" runat="server" associatedcontrolid="textbox1">name</asp:label>         <asp:textbox id="textbox1" runat="server" text='<%# bind("name") %>' />          <asp:label id="label2" runat="server" associatedcontrolid="textbox2">data</asp:label>         <asp:textbox id="textbox2" runat="server" text='<%# bind("meddate", "{0:d}") %>' />          <asp:linkbutton id="updatebutton" runat="server"             causesvalidation="true" commandname="update"         </asp:linkbutton>     </edititemtemplate> </asp:listview> 

note updatemethod="updatefile" , textbox2 bind("meddate", "{0:d}").

finally here updatedfile in code behind:

public void updatefile(guid medfileid) {     // current med file db     medfile medfile = _cartellabll.getmedfilebyfileid(medfileid);     // update values taken web form     tryupdatemodel(medfile);     // save updated med file     if (modelstate.isvalid) {        _cartellabll.updatefile(medfile);     }     ... } 

as known, above tryupdatemodel(medfile) auto-magically validates, parses , converts fields in web form updating passed medfile variable.

in particular, validates , converts value of textbox2 according date format of application's culture possibly set in web.config file:

<globalization culture="it-it" uiculture="it-it" /> 

my problem i'd user able set date in webform using 1 of 2 possible formats: 1 of default culture, in case dd/mm/yyyy (italy), , international yyyy-mm-dd (iso 8601).

is possible instruct tryupdatemodel(tmodel) 'accept' both format?


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -