Problem with spaces in values of the DataTextField property of datagrid control

Discussion in 'ASP .Net Web Controls' started by chorus_charms@yahoo.com, Jul 3, 2006.

  1. Guest

    Hi,

    I am using a datagrid control to display the values from a database
    table.

    I have used a Button Column with the DataTextField Column set to the
    field in the db table, from where I need to populate values. It is
    basically a Report Name.
    The problem is that if the Report name contains spaces, the same is
    rendered on the Datagrid column without spaces.

    In other words, if I saved a report name as "joe black" or "joe
    black" or "joe black", it is always displayed as
    "joe black" on the grid control.
    The db table saves the name correctly.

    Can anyone suggest some way to overcome this problem??

    Thanks,
    Sadhvi M
     
    , Jul 3, 2006
    #1
    1. Advertising

  2. Guest

    Your problem lies with the way browsers interpret whitespace in HTML.
    Most browsers would render 1 space even though there are multiple
    spaces in the source HTML.

    A suggestion to preserve spaces is to replace each space in the report
    name with the   html entity. You do the replacement after reading
    the values out of the database and before doing a databind on the
    gridview.

    Another suggestion to preserve spaces is to enclose the report name
    with the <pre> tag.

    Andy.

    wrote:
    > Hi,
    >
    > I am using a datagrid control to display the values from a database
    > table.
    >
    > I have used a Button Column with the DataTextField Column set to the
    > field in the db table, from where I need to populate values. It is
    > basically a Report Name.
    > The problem is that if the Report name contains spaces, the same is
    > rendered on the Datagrid column without spaces.
    >
    > In other words, if I saved a report name as "joe black" or "joe
    > black" or "joe black", it is always displayed as
    > "joe black" on the grid control.
    > The db table saves the name correctly.
    >
    > Can anyone suggest some way to overcome this problem??
    >
    > Thanks,
    > Sadhvi M
     
    , Jul 4, 2006
    #2
    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. Mark Rae
    Replies:
    5
    Views:
    5,374
    Mark Rae
    Jan 12, 2007
  2. John B. Matthews
    Replies:
    4
    Views:
    681
    John B. Matthews
    Sep 12, 2008
  3. Roedy Green
    Replies:
    3
    Views:
    641
  4. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,633
    Jan C. Faerber
    Sep 10, 2009
  5. Andrew Todd

    Multiple datatextfield values in checkboxlist

    Andrew Todd, Aug 13, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    666
    Andrew Todd
    Aug 13, 2003
Loading...

Share This Page