Click here to Skip to main content
15,887,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to limit column character length in gridview of asp.net
Posted
Updated 28-Aug-11 16:16pm
v2

You want to mean restricting cell value ? GridView Data is coming from a data source only why you are not checking that data source value before biding ? GridView having an excellent powerful method called "RowDataBound", there you can restrict the number of character.
Or you are talking about character limit for Edit and Insert records from gridview ?
 
Share this answer
 
Comments
Sachin gulati 28-Aug-11 22:26pm    
no no.... i m talking about the no. of characters it shows....
tell me about rowdatabound... will it work??
Abhijit Jana 28-Aug-11 22:46pm    
Yes, That will work .
If you are using TemplateField to Bind the data, you can do it on design page itself. This thread will help you http://forums.asp.net/t/1136480.aspx/1
string txt = Server.HtmlDecode(((Label)e.Row.FindControl("lblDescription")).Text);
string newTxt = (txt.Length > 415 ? txt.Substring(0, 415) + "..." : txt + "...");
((Label)e.Row.FindControl("lblDescription")).Text = Server.HtmlDecode(newTxt);

//////////
this is an easiest way through row databound plz check once
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900