Home All Groups Group Topic Archive Search About

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

Author
3 Jul 2006 4:28 PM
chorus_charms
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

Author
3 Jul 2006 11:09 PM
CaffieneRush@gmail.com
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.

chorus_cha***@yahoo.com wrote:
Show quoteHide quote
> 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