Re: How to use formatting expression on DataGrid bound column.

Discussion in 'ASP .Net' started by Sonali.NET[MVP], Jun 25, 2003.

  1. Refer
    http://www.c-sharpcorner.com/Code/2003/June/FormatDataGridData.asp
    http://www.c-sharpcorner.com/Code/2003/June/DataFormatString.asp

    HTH
    Regards
    Sushila
    ..NET MVP

    "Manu" <> wrote in message news:0c8a01c33a96$dac16a40$...
    > When Creating a DataGrid it possible format every item
    > using the DataGrid Property builder.
    > In the builder under Bound column we will find data
    > formatting expression field which according to MS help
    > should contain an expression that will be applied on the
    > column's data before presenting it. For example it is
    > written that transforming Date/time format to a short
    > presentation should be done here. It was not written HOW
    > to write these formatting expressions.
    >
    > I would like to show a field of type Date/Time in it's
    > short version (only dd/mm/yyyy) in a DataGrid. What
    > expression should I use in the data formatting expression
    > field?
    >
     
    Sonali.NET[MVP], Jun 25, 2003
    #1
    1. Advertising

  2. Sonali.NET[MVP]

    TimDay

    Joined:
    Jul 30, 2006
    Messages:
    2
    Location:
    Atlanta
    I used the following formatting expression for dates and it seemed to work: {0:MM/dd/yyyy}
     
    TimDay, Jul 30, 2006
    #2
    1. Advertising

  3. Sonali.NET[MVP]

    TimDay

    Joined:
    Jul 30, 2006
    Messages:
    2
    Location:
    Atlanta
    Go to this web site for more information, such as that below: http://msdn2.microsoft.com/en-us/library/c76820yk.aspx.

    Data formatting expression
    A .NET Framework formatting expression that is applied to the data before it is displayed in the column. The expression consists of optional static text and a format specifier that takes the following form:
    {0:format specifier}
    The number in front of the colon :)) is a parameter index that indicates which data elements in the column to format; it is therefore usually zero to indicate the first (and only) element. The format specifier follows the colon and consists of one or more letters that indicate how to format the data. The format-specifier characters you can use depend on what type of data you are formatting — dates, numbers, or other types. The following table shows examples of formatting expressions for different types of data. For more information about formatting expressions, see Formatting Types.

    Format expression Applied to this data type Description
    Price: {0:C} numeric/decimal Displays the literal string "Price:" followed by numbers in currency format. The currency format depends on the culture setting specified through the culture attribute on the @ Page directive or in the Web.config file.
    {0:D4} integer (Cannot be used with decimal numbers.) Integers are displayed in a zero-padded field four characters wide.
    {0:N2}% numeric Displays the number with 2-decimal-place precision, followed by the literal string "%".
    {0:000.0} numeric/decimal Numbers rounded to one decimal place. Numbers less than three digits are zero-padded.
    {0:D} date/datetime Long date format ("Thursday, August 06, 1996"). Date format depends on the culture setting of the page or the Web.config file.
    {0:d} date/datetime Short date format ("12/31/99").
    {0:yy-MM-dd} date/datetime Date in numeric year-month-day format (96-08-06).
     
    TimDay, Jul 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    0
    Views:
    426
  2. John E.
    Replies:
    3
    Views:
    4,485
    masoud bayan
    Mar 25, 2005
  3. Just Me
    Replies:
    1
    Views:
    403
    Mark Rae [MVP]
    Oct 30, 2007
  4. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    231
    Ravichandran Mahalingam
    Jan 9, 2004
  5. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    240
    Elton Wang
    Mar 28, 2005
Loading...

Share This Page