Solved

limit character length in gridview cell

Posted on 2008-11-03
5
2,207 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now