Qualcosa su di me

Mi chiamo Andrea Moro, sono un appassionato di informatica da quando avevo 8 anni e da quando mio padre mi regalò il C64.

Qualche anno più tardi, il mio primo pc e nel 1994 la prima esperienza con Internet, di cui mi sono subito innamorato e con cui oggi mando avanti la mia attività di Web Designing e posizionamento nei motori di ricerca.

View Andrea Moro's profile on LinkedIn

Profilo Facebook di Andrea Moro

Calendar

<<  gennaio 2009  >>
lumamegivesado
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar


RSS

If you are looking for an answer why DataFormatString won't be applied at your BoundField, the most reasonable answer is "It's a bug". A bug for which nobody at Microsoft seems to be responsible for.

In few words, if you have a BoundField object bound to a field of type DateTime (or whatever you want) with a DataFormatString like this:

<asp:BoundField DataField="DateOfBirth" DataFormatString="{0:MM/dd/yyyy}" />

when you will run your web application, the output instead to be as everybody would expect (MM/dd/yyyy) appears to be formatted using its ToString() method like so:

07/02/2007 7:35:54 PM

The problem is reconducible to an effort of preventing cross site scripting attacks, so the field value is HtmlEncoded before the new formmating is applied. This internally changes the output that doesn't match anymore to a suitable Date format and for this reason the format requested won't apply.

The resolution is to set up the HtmlEncode to false like so:

<asp:BoundField DataField="DateOfBirth" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false"/>

Technorati Tags: ,

Vota questo post per primo

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Aggiungi commento


(Visualizza la tua icona Gravatar)

  Country flag

biuquote
  • Commento
  • Anteprima
Loading



Advanced Technology

Abruzzo SEO specialist, .Net programming and computer stuff