Showing posts with label formatting. Show all posts
Showing posts with label formatting. Show all posts

Wednesday, January 5, 2011

Formatting DateTime databound fields in ASP.NET in asp:Label

Here's how to format it in code-behind code:
/* Displays the date and time as "05 Jan 2011 16:25"in a Label control inside a FormView control */
DateTime datetime = DateTime.Now; Label lblDateOfEntry = (Label)FormView1.FindControl("LabelDateOfEntry") lblDateOfEntry.Text = String.Format("{0:dd MMM yyyy HH:mm}", datetime); 

And here's how to format it in Markup code

<asp:Label ID="LabelDateOfEntry" runat="server" Text='<%# Bind("DateOfEntry","{0:dd MMM yyyy HH:mm}") %>' >

Thursday, May 31, 2007

Formatting Strings

Standard Numeric Format Strings

Custom Numeric Formats

Example : Convert a double into a string with 2 decimal places
Dim PercentStat As Double = 3.1423489955
Dim PercentStr As String = PercentStat.ToString("#0.00")