Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 549139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:09:11+00:00 2026-05-13T11:09:11+00:00

using Telerik RadGrid* in a LINQ context, with ASP.NET/C#, how to truncate text to

  • 0

using Telerik RadGrid* in a LINQ context, with ASP.NET/C#, how to truncate text to a maximum length when displaying in columns? By maximum, I mean if original string’s length is shorter than the specified maximum length, no errors will raise.

I have seen many examples of this on the net, but it seems that the Container.DataItem used to achieve this is different when using LINQ. Sometimes we see DataItem as a method, sometimes not. Examples are usually using a DataSet.

Here’s an example found (source) :

<asp:TemplateField HeaderText="Description">
  <ItemTemplate>
    <%# ValidateString(Container.DataItem("Description")) %>
  </ItemTemplate>
</asp:TemplateField>

And codebehind:

protected string ValidateString(object String)
{
  if ((String.ToString().Length > 50))
  {
    return String.ToString().Substring(0, 50) + "...";
  }
  else
  {
    return String.ToString();
  }
}

Thank you for the help.

(*) Or a normal GridView, supposed to be compatible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:09:11+00:00Added an answer on May 13, 2026 at 11:09 am

    I would hook into the OnItemDataBound event and perform this in your code behind. Cast the data item as your custom object and query the property, something like the following (typing some from memory):

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
         if (e.Item is GridDataItem)
         {
              GridDataItem dataBoundItem = e.Item as GridDataItem;
              CustomObject o = e.Item.DataItem as CustomObject;
    
              if(o.Description.Length > 50)
              {
                   dataBoundItem["Description"].Text = o.Description.Substring(0, 47) + "..."
              }
          }
    }
    

    Alternatively if you want to stick with the method you are using try the following in your aspx

    <telerik:GridTemplateColumn>
         <ItemTemplate>
              <%# ValidateString(Eval("Description").ToString()) %>
         </ItemTemplate>
    </telerik:GridTemplateColumn>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using a Telerik Radgrid on ASP.Net 3.5 and whenever I postback, the selectedindex
I am using a Telerik RadGrid in ASP.Net framework. I create Buy procedure and
Using RadGrid for Asp.Net Ajax (from Telerik) I need to re-set the CurrentPageIndex. Some
I have an ASP.NET application using the Telerik Q1 2009 controls. I have a
I am using Telerik asp.net mvc extensions. I have an issue that happens only
Currently using Telerik ASP .NET MVC Controls version 2011.2.712 Hello all, I am trying
I am using Telerik's Radgrid for a website. Often the grid columns exceed the
I'm using the Telerik ASP.net control suite (2008 Q3 I believe, can't upgrade yet).
Ive no problems using Javascript to read the rows of a telerik radgrid component
Using VS2008, and Telerik radGrid version 2010.1.519.35 I have a about 50 DNN modules

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.