Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

limit character length in gridview cell

Posted on 2008-11-03
5
2,287 Views
Last Modified: 2009-04-13
I have a field in the database that have up to 1000 characters in it.  In my gridview I only want to show the first 100 characters in that column, but when they click the view/edit link then it will show all the text.

Does anyone have a simple way of doing this?  Thanks.
0
Comment
Question by:andy12279
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22867570
Perhaps this example can help you: Dynamic Gridview - Adding a max length to the edit textbox
http://forums.asp.net/t/1233788.aspx
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 125 total points
ID: 22869553
quite simple
add a template filed for description and code as shown belwo
<asp:TemplateField ItemStyle-HorizontalAlign="left" ItemStyle-Width="170px" HeaderText="Description" >
	<ItemTemplate>
		<%# Eval ("Description").ToString ().Length > 100 ? Eval ("Description").ToString ().Substring (0, 100) + "&" : Eval("Description").ToString ()%>
	</ItemTemplate>
</asp:TemplateField>

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22890716
Even simpler:
<asp:TemplateField ItemStyle-HorizontalAlign="left" ItemStyle-Width="170px" HeaderText="Description" >
	<ItemTemplate>
		<%# Eval ("Description").ToString ().Substring (0, 100)%>
	</ItemTemplate>
</asp:TemplateField>

Open in new window

0
 
LVL 2

Author Comment

by:andy12279
ID: 22890738
Yes prairidog that will work but if the string is less than 100 characters it will throw an error.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22890788
Really? I thought it will just ignore the second parameter if the length is less than 100. Well, I was wrong.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question