This is a migrated thread and some comments may be shown as answers.

Show leading and trailing spaces in a radgrid column.

5 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nilanjan
Top achievements
Rank 1
Nilanjan asked on 12 Mar 2009, 11:22 AM
I am trying to show a text value in a radgrid column cell that contains leading spaces, for example :-    '      111'.
The value is present in the td element when i view the source of the page,  but it is not shown in the browser. The grid in browser trims the leading spaces and displays  just   '111'.  How can i show the leading spaces in the grid column cell, without appending    before?
But when i sort the column it considers the leading spaces,  as it is present in the datasource. The end user finds it as a mismatch between what he enters in UI field and what he sees in grid. Please advice how to handle the situation.

5 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 13 Mar 2009, 09:40 AM
Hello Nilanjan,

Stripping spaces in HTML output is a browser behavior. You can change it if you set DataFormatString to "<pre>{0}</pre>" for the specific column (or all columns), either declaratively or programmatically (for programmatic settings, please use the ColumnCreated event)

ASPX

<telerik:GridBoundColumn DataFormatString="<pre>{0}</pre>"  />

C#

    protected void RadGrid_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
    {
        if (e.Column is GridBoundColumn)
        {
            (e.Column as GridBoundColumn).DataFormatString = "<pre>{0}</pre>";
        }
    }

The <pre> element has a special font family style by default, but you can change it with CSS:

CSS

pre
{
     font:12px arial,sans-serif;
}


Kind regards,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kurt Wondra
Top achievements
Rank 2
answered on 14 Sep 2010, 04:25 PM
Thank you for the simple, and easy fix.  This helped me as well.
0
Sachin
Top achievements
Rank 1
answered on 10 Oct 2013, 08:56 PM
How would do it if were a GridTemplateColumn. 
I have a label inside a GridTemplateColumn and would like display the text as is. I want to do it dynamically in the code behind if possible.
How can I set to the <pre> for a label inside a GridTemplateColumn

 <telerik:GridTemplateColumn HeaderText="Debtor Name" UniqueName="GridDebtorName"
                    Groupable="false">
                    <ItemTemplate>
                            <asp:Label ID="GridDebtorNameLabel" runat="server" Text='<%# String.Format("<pre>{0}</pre>", DataBinder.Eval(Container.DataItem, "OrganizationName")) %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle Width="145px" />
                </telerik:GridTemplateColumn>

I have a text that has HTML Special characters in them like "aaa &amp; bbbb" and i would like to display it as it is. But even with the above change, i see "aaa & bbb" on the browser.
0
Sachin
Top achievements
Rank 1
answered on 10 Oct 2013, 10:01 PM
Ok i figured it out. I should use the xmp tag since pre does interprets &amp; as &
0
devoas
Top achievements
Rank 1
answered on 09 Apr 2016, 08:53 AM

Hi,

We are creating Grid Object and its columns Dynamically and adding it in asp page.... We also faced above issue, while attaching this even ColumnCreated, In that event ColumnCreated,  ->  we could not found any column maching  if (e.Column is GridBoundColumn) .... 

Can you pls help how to check it for particular column and apply it...  Also Confirm what to be done to export Leading Spaces to Excel.

 

Thanks.

 

Tags
Grid
Asked by
Nilanjan
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Kurt Wondra
Top achievements
Rank 2
Sachin
Top achievements
Rank 1
devoas
Top achievements
Rank 1
Share this question
or