Show leading and trailing spaces in a radgrid column.

6 posts, 0 answers
  1. Nilanjan
    Nilanjan avatar
    26 posts
    Member since:
    May 2008

    Posted 12 Mar 2009 Link to this post

    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.
  2. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 13 Mar 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kurt Wondra
    Kurt Wondra avatar
    7 posts
    Member since:
    Oct 2009

    Posted 14 Sep 2010 Link to this post

    Thank you for the simple, and easy fix.  This helped me as well.
  5. Sachin
    Sachin avatar
    2 posts
    Member since:
    Oct 2013

    Posted 10 Oct 2013 Link to this post

    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.
  6. Sachin
    Sachin avatar
    2 posts
    Member since:
    Oct 2013

    Posted 10 Oct 2013 Link to this post

    Ok i figured it out. I should use the xmp tag since pre does interprets &amp; as &
  7. devoas
    devoas avatar
    69 posts
    Member since:
    Dec 2009

    Posted 09 Apr in reply to Dimo Link to this post

    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.

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017