Runtime DataGrid formating

Discussion in 'ASP .Net' started by Tina, Dec 21, 2004.

  1. Tina

    Tina Guest

    I have a datagrid where I specified {0:###,###,###} at design time. However
    sometimes I am putting percentages in the grid instead of money and I want
    to change the formating to {##%}. I've looked over the docs on such things
    as the dataformatstring porperty of the boundColumn but still can't figure
    out how to do it in code.

    Thank,
    T
     
    Tina, Dec 21, 2004
    #1
    1. Advertising

  2. Tina

    Joseph Lee Guest

    This is what I did, it is not very good, but will allow you to do
    processing.

    Example:
    On the aspx/ascx page, I would like to retrieve the the date for the the
    particular record
    so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
    pass in the record in the datagrid

    <%# GetDate(Container.DataItem) %>

    On the aspx.cs/ascx.cs, I will process the dataItem, which return the short
    date for my datagrid

    public string GetDate(Object obj)
    {
    string topicDate = ((DataRowView)obj)["topicDate"].ToString();
    return Convert.ToDateTime(topicDate).ToShortDateString();
    }

    -----------------------------------------------------------------

    If you would like a better and much more professional way, this article
    might help

    http://openmymind.net/databinding/index.html

    Joey

    "Tina" <> wrote in message
    news:...
    >I have a datagrid where I specified {0:###,###,###} at design time.
    >However sometimes I am putting percentages in the grid instead of money and
    >I want to change the formating to {##%}. I've looked over the docs on such
    >things as the dataformatstring porperty of the boundColumn but still can't
    >figure out how to do it in code.
    >
    > Thank,
    > T
    >
     
    Joseph Lee, Dec 22, 2004
    #2
    1. Advertising

  3. Tina

    Tina Guest

    Ouch, pretty ugly but thank you for the help. The article is also very
    good.
    T

    "Joseph Lee" <> wrote in message
    news:%...
    > This is what I did, it is not very good, but will allow you to do
    > processing.
    >
    > Example:
    > On the aspx/ascx page, I would like to retrieve the the date for the the
    > particular record
    > so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
    > pass in the record in the datagrid
    >
    > <%# GetDate(Container.DataItem) %>
    >
    > On the aspx.cs/ascx.cs, I will process the dataItem, which return the
    > short date for my datagrid
    >
    > public string GetDate(Object obj)
    > {
    > string topicDate = ((DataRowView)obj)["topicDate"].ToString();
    > return Convert.ToDateTime(topicDate).ToShortDateString();
    > }
    >
    > -----------------------------------------------------------------
    >
    > If you would like a better and much more professional way, this article
    > might help
    >
    > http://openmymind.net/databinding/index.html
    >
    > Joey
    >
    > "Tina" <> wrote in message
    > news:...
    >>I have a datagrid where I specified {0:###,###,###} at design time.
    >>However sometimes I am putting percentages in the grid instead of money
    >>and I want to change the formating to {##%}. I've looked over the docs on
    >>such things as the dataformatstring porperty of the boundColumn but still
    >>can't figure out how to do it in code.
    >>
    >> Thank,
    >> T
    >>

    >
    >
     
    Tina, Dec 22, 2004
    #3
  4. Tina

    Tina Guest

    Joseph,
    I found a way to do it without having to put code manually into the .aspx
    file.
    In the ItemDataBound event just do:
    myString = e.item.Cells(x).text 'the number without editing mask
    myInteger = val(myString)
    e.item.cells(x).text = myInteger.tostring("##%")

    Works great!
    T


    "Joseph Lee" <> wrote in message
    news:%...
    > This is what I did, it is not very good, but will allow you to do
    > processing.
    >
    > Example:
    > On the aspx/ascx page, I would like to retrieve the the date for the the
    > particular record
    > so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
    > pass in the record in the datagrid
    >
    > <%# GetDate(Container.DataItem) %>
    >
    > On the aspx.cs/ascx.cs, I will process the dataItem, which return the
    > short date for my datagrid
    >
    > public string GetDate(Object obj)
    > {
    > string topicDate = ((DataRowView)obj)["topicDate"].ToString();
    > return Convert.ToDateTime(topicDate).ToShortDateString();
    > }
    >
    > -----------------------------------------------------------------
    >
    > If you would like a better and much more professional way, this article
    > might help
    >
    > http://openmymind.net/databinding/index.html
    >
    > Joey
    >
    > "Tina" <> wrote in message
    > news:...
    >>I have a datagrid where I specified {0:###,###,###} at design time.
    >>However sometimes I am putting percentages in the grid instead of money
    >>and I want to change the formating to {##%}. I've looked over the docs on
    >>such things as the dataformatstring porperty of the boundColumn but still
    >>can't figure out how to do it in code.
    >>
    >> Thank,
    >> T
    >>

    >
    >
     
    Tina, Dec 23, 2004
    #4
    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. =?Utf-8?B?VGF5bw==?=

    Datagrid formating

    =?Utf-8?B?VGF5bw==?=, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,436
    Raterus
    May 24, 2004
  2. Formating DataGrid/View

    , Feb 22, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    392
  3. Harley

    conditional formating on Datagrid control

    Harley, Jul 29, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    132
    Saravana
    Jul 31, 2003
  4. Tina

    runtime formating change

    Tina, Dec 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    120
    Jason
    Jan 3, 2005
  5. Annie

    Datagrid formating to be inherited by all others

    Annie, Sep 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    119
    Annie
    Sep 9, 2005
Loading...

Share This Page