Limit amount of text shown in data column

6 posts, 0 answers
  1. Ron
    Ron avatar
    113 posts
    Member since:
    Apr 2011

    Posted 06 Aug 2011 Link to this post

    Hi,

    Can you tell me if there is a way to limit the amount of text shown in rad grid? For example; a particular data field has a string of text about 200 characters in length, but on the actual data grid I only want to show the first 50 characters in the data column. How would I do that?
    Looking forward to assistance.

    Thanks,
    Ron.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 07 Aug 2011 Link to this post

    Hello,


    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"
                     >
                       </telerik:GridBoundColumn>
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
                    if (item["Name"].Text.Length > 200)
                    {
                       item["Name"].Text = item["Name"].Text.Substring(0, 200);
                    }
                }
            }

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rakesh Gupta
    Rakesh Gupta avatar
    12 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2011 Link to this post

    Hello,
    You can achieve this by using following code.

    .aspx:
    <telerik:GridTemplateColumn HeaderText="Short Description"
    DataField="Description" SortExpression="Description" AllowFiltering="true" UniqueName="Description" Visible="true">
         <HeaderStyle HorizontalAlign="Left" />
         <ItemTemplate>
              <asp:Label runat="server" ID="lblDescription" Text='<%# Eval("Description") %>'></asp:Label>
          </ItemTemplate>
          <ItemStyle Wrap="True" HorizontalAlign="Left" />
    </telerik:GridTemplateColumn>
    .aspx.cs
    RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
         if (e.Item is GridDataItem)
         {
              Label lblDescription= (Label)e.Item.FindControl("lblDescription");
                
              if (lblDescription.Text.Length > 50)
                   lblDescription.Text = lblDescription.Text.SubString(0,50);
        }
    }

    Above code will display first 50 characters if the characters are more than 50.

    Let me know for any concerns.

    --
    Thanks & Regards,
    Rakesh T. Gupta
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 08 Aug 2011 Link to this post

    Hello Rakesh.

    Its also work but if you take one more Lable to showing the data then it will affect the Grid's performance (on Live Server).

    Please compare the page source code in both sample.

    Thanks,
    Jayesh Goyani
  6. Harish
    Harish avatar
    11 posts
    Member since:
    Jun 2015

    Posted 07 Jul 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    I want the same scenario but only thing I am using RadEditor control.

    In RadEditor control I have some formatted test(Bold,Italic). Now from the formatted content I want to show the only first 50 character. If I will try the above code which mentioned you It will not bind the formatted text.

    I am getting from database

    Content Saved in Database:
    <strong><em><span style="font-size: 20px;
    text-decoration: underline; color: #ff0000; background-color:
    #ffc000;">WOW <span style="color: #000000; background-color:
    #ffffff;">12356432569874563215346985763259874561235478965324</span></span></em></strong>

    How to achieve this ?

    Thanks,

    Harish P

  7. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 10 Jul 2015 Link to this post

    Hi Harish,

    The question you posted has already been answered in the following forum thread: http://www.telerik.com/forums/radeditor-shows-only-50-character-from-content. I would recommend continuing the discussion there as it will be easier to track the information on the case when it is in one place.

    Regards,
    Slav
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017