简体   繁体   中英

Data binding Textbox with individual format

I would like to format a date in a bound textbox to a date format specified by the user itself (not related to the international settings of the specific computer). Ie for some of the users the date format should be mm/dd/yyyy and for others it should be dd.mm.yyyy - depending on the user settings from the database.

I need to replace the {0:d} from this code to something else which solves my issue:

<asp:TextBox ID="UBirthDateTextBox" runat="server" Text='<%# Bind("UBirthDate", "{0:d}") %>' />

Btw: I have stored the date format for the specific user in the session variable "DFormat"

Does some of you cracks have an idea how to solve that?

Given your parameters - you want to bind the textbox - the first thing that occurs is:

  1. Create a public function on your page that returns a format string for the date, based on the value in the database. Depending on how you have the format string stored, you may have to construct something appropriate rather than just return it.

  2. Refer to the function in your markup:

     <asp:TextBox ID="UBirthDateTextBox" runat="server" Text='<%# Bind("UBirthDate", GetDateFormatString()) %> 

It's been a long time since I tried something like this, but I believe that if the function is public and on the page, it can be referred to in the markup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM