How do I wrap contents of long non space text in a RadGrid column?

7 posts, 0 answers
  1. thees
    thees avatar
    7 posts
    Member since:
    Sep 2010

    Posted 10 Dec 2010 Link to this post

    How do I wrap contents of long non space text in a RadGrid column?
    Please review the attachment.
    I tried following code ,it not helping.
    Thank you.
    <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" UniqueName="ShipName"
                 <ItemStyle Wrap="false" Width="50px"  /> 
    </telerik:GridBoundColumn>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Dec 2010 Link to this post

    Hello Thees,

    Give a try with the following approach to achieve this.
    ASPX:
    <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName"
                            UniqueName="ShipName">
      <HeaderStyle Wrap="false" Width="50px" />
    </telerik:GridBoundColumn>

    Also  go through the following documentation which explains how to prevent the wrapping for column cells content.
    No wrap for grid cell content

    Thanks,
    Princy.
  3. thees
    thees avatar
    7 posts
    Member since:
    Sep 2010

    Posted 12 Dec 2010 Link to this post

    Hi,
    Sorry i included wrong code.Basically i need to wrap the cell.
    I tried both codes
    <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName"  ItemStyle-Wrap="true" SortExpression="ShipName" UniqueName="ShipName">
                 <ItemStyle Wrap="true" Width="50px"  />
    </telerik:GridBoundColumn>


    <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName"
                            UniqueName="ShipName">
      <HeaderStyle Wrap="true" Width="50px" />
    </telerik:GridBoundColumn>

    When the string have space it working correctly,it is not working when string don't have space.
    Thank you.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Dec 2010 Link to this post

    Hi,


    For the wrap to take place properly, the cell text must contain white space in between. But in your case, unfortunately, there is no space in the item text. In this situation one possible option would be to setting the tooltip for cell , which would show the complete text of the cell, when the user hovers over it and cut the cell text to particular length (and show ellipsis for cell text).

    You can perform this in ItemDataBound event of grid.
    Accessing cells and rows


    -Shinu.
  5. Chris Poirier
    Chris Poirier avatar
    11 posts
    Member since:
    Mar 2007

    Posted 22 Sep 2011 Link to this post

    I was facing the same problem, and I have found a solution that works in all major browsers (IE7 specific CSS is required).

    1) The width of the grid must be set in pixels. (Only necessary for IE7.)
    2) Assign an ItemStyle.CSSClass to the column. (For this example, I have used "itemNameColumn")
    3) Add the following to your CSS file:
    .itemNameColumn span
    {
        display: block;
        width: 225px; /* Set this to the width you want to break at. */
        word-wrap: break-word; /* This will not be recognized by Visual Studio, but it works. */
    }
    4) For IE7, add the following CSS: (I used a conditional comment to create an IE7 specific CSS file)
    .itemNameColumn
    {
        position: relative;
    }
    .itemNameColumn span
    {
        position: absolute;
        left:0;
    }

    Now it will break in the middle of a long word and will not break the styling of the table.
  6. Max T
    Max T avatar
    3 posts
    Member since:
    Oct 2014

    Posted 31 Oct 2014 Link to this post

    You could also try to use ItemDataBound code to wrap the text manually. That's what i ended up having to do.

    If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then
       'Get a reference to the current item
       Dim gdiItem As GridDataItem = e.Item
     
       If gdiItem("settings_value_short").Text.Length > 50 Then
          Dim strValue As String = gdiItem("settings_value_short").Text
          Dim intStringLength As Integer = gdiItem("settings_value_short").Text.Length
          Dim intSection As Integer = (intStringLength - (intStringLength Mod 50)) / 50
          While intSection > 0
             strValue = strValue.Substring(0, intSection * 50) & "<br />" & _
                     strValue.Substring(intSection * 50)
             intSection -= 1
          End While
          gdiItem("settings_value_short").Text = strValue
       End If
    End If
  7. Disposable Hero
    Disposable Hero avatar
    3 posts
    Member since:
    Oct 2018

    Posted 08 Aug Link to this post

    I just referenced this style in ItemStyle-CssClass="wrapWord" attribute.

    .wrapWord { word-wrap: break-word;word-break:break-all;}

Back to Top