Truncate String in RadGrid or GridView

Posted on: Fri Feb 05 15:10:10 -0800 2010. Updated on: Fri Feb 05 15:43:12 -0800 2010.
Category: Telerik Controls and Sitefinity

Sometimes on display, when we have fields that may contain long text, we want to truncate the max length that is displayed on screen. It is easy to do this. First change the column into a Template, then when binding call a function you define.

// put this method in your code behind
protected string TruncateString(object stringToValidate)
		{
			string output = Convert.ToString(stringToValidate);
			
			if (output.Length > 30)
			{
				return output.Substring(0, 30) + "...";
			}
			else
			{
				return output;
			}
		}

Now in your template in the RadGrid, simply do this when outputting the text:
TruncateString(Eval("PartnerNotes"))

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.