Specify Format String For Auto-Generated Datagrid Column?

Discussion in 'ASP .Net' started by Joey Powell, Jan 18, 2004.

  1. Joey Powell

    Joey Powell Guest

    Is it possible to specify a format string for one or more
    auto-generated datagrid columns? If so, could someone post an example?
    More specifically, I am interested in taking output like 27.0800000
    and turning it into 27.08

    I have also tried doing this with the underlying SQL statement, but I
    can't get it to work that way, either.
    Joey Powell, Jan 18, 2004
    #1
    1. Advertising

  2. Joey Powell

    MSFT Guest

    Hi Joey,

    Thank you for using MSDN Newsgroup. I am Luke and I am review this issue
    currently. From your description, you want to format the output in a
    datagrid, for example, from 27.0800000 to 27.08. The data is retrieve from
    a database.

    Regarding the question, if the database is SQL server, I think the easiest
    way is doing with the underlying SQL statement, for example:

    select CONVERT(decimal(15,2), DecColumn) as DecimalField from Table1

    As you the Convert function in SQL server can format the decimal column
    with 2 bits scale. We only need to modify the SelectCommand of the
    DataAdapter like this.

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    MSFT, Jan 19, 2004
    #2
    1. Advertising

  3. Im running into the a very similar situation.

    The only difference is that my data does not come from any database
    whatsoever. In fact it comes from a variety of files the user can upload, it
    is then stored in a collection of objects I designed and finally displayed
    in a datagrid. Is there a way to format data in this scenario?

    Thanks

    Juan Ramon


    "MSFT" <> escribió en el mensaje
    news:...
    > Hi Joey,
    >
    > Thank you for using MSDN Newsgroup. I am Luke and I am review this issue
    > currently. From your description, you want to format the output in a
    > datagrid, for example, from 27.0800000 to 27.08. The data is retrieve from
    > a database.
    >
    > Regarding the question, if the database is SQL server, I think the

    easiest
    > way is doing with the underlying SQL statement, for example:
    >
    > select CONVERT(decimal(15,2), DecColumn) as DecimalField from Table1
    >
    > As you the Convert function in SQL server can format the decimal column
    > with 2 bits scale. We only need to modify the SelectCommand of the
    > DataAdapter like this.
    >
    > Hope this help,
    >
    > Luke
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    Juan Ramon Martinez, Jan 19, 2004
    #3
  4. Joey Powell

    MSFT Guest

    Hi Juan,

    In this situation, we may change text's format of datagrid cell in its
    ItemDataBound. You may refer to follow article as a sample:

    http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q313154

    In above article, he change some special cell's format. We can apply the
    way in the cells we want.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    MSFT, Jan 20, 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. Jason
    Replies:
    3
    Views:
    17,015
    Jan Hyde
    May 8, 2006
  2. linkswanted
    Replies:
    1
    Views:
    876
  3. Dave

    Format Phone Number String in Datagrid Column

    Dave, Dec 5, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    269
  4. susie

    specify the width of dynamically generated textboxes

    susie, Oct 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    151
    Victor Garcia Aprea [MVP]
    Oct 23, 2003
Loading...

Share This Page