Home > ASP.Net > Displaying only 15 characters in GridView data field

Displaying only 15 characters in GridView data field


Hi

try this example:

<ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# TrimText(DataBinder.Eval(Container, "DataItem.Description").ToString(), 15) %>'></asp:Label>
 </ItemTemplate>

and in codebehind :

public static string TrimText(string text, int chars)
{

string newtext= "";

if (text.Length <= chars)

 {
   newtext= text;
 }

else
 {
   newtext= text.Substring(0, chars - 4) + "...";
 }

return newtext;

}

Hope it helps

also i post another example you can check it

https://yasserzaid.wordpress.com/2009/01/10/limit-text-length-in-gridview/

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: