Solved

asp.net gridview string length

Posted on 2008-10-30
7
726 Views
Last Modified: 2012-06-21
In gridview I want to restrict the output of a field to a fixed string length.  For example, I want to restrict this field content:
"example text and a lot more more more more more"
to 20 characters, like this:
"example text and a lo..."
How do I do this please?


0
Comment
Question by:david_mo
[X]
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
  • 3
  • 2
7 Comments
 
LVL 12

Expert Comment

by:techExtreme
ID: 22843470
Hello,
for that you have to use itemtemplate column for your column and use a div inside it and place your content in it. Then you have to do clipping on the div.
Look at this tutorial, explains possible clipping options:
http://www.w3.org/TR/CSS2/visufx.html
This way you can restrict your grid from increasing size according to the text received in column.
Let me know if I misunderstood something.
Hope it helped.
0
 

Author Comment

by:david_mo
ID: 22843677
Thanks but I don't really understand how this solves it.  I don't want to create a box.  I just want to clip the length of the text in a particular field.  An example of what I want is on Experts Exchange.  If you use the search, the output gives a list of results with the comments field clipped to the same length for each result.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22843899
Hi,
Well the easiest way you can go for is to handle your grid's rowdatabound event and fetch the item in a string, then say you want to limit it to 20 (including the three characters '...') then if it exceeds 17 chars, you take first 17 chars, concat with ... and put it in the label  instead of directly binding the dataitem to the label.
This way you can have the same result you want  at max the text will be 20 chars wide.
0
 

Author Comment

by:david_mo
ID: 22844348
Thanks but sorry, I did say I was a beginner.  With respect only another expert could understand this.
I'm searching the internet trying to understand the meaning of the words you're using.
0
 
LVL 12

Accepted Solution

by:
techExtreme earned 500 total points
ID: 22850566
Hi,
No problem, I assumed you might knew that. Anyways I've compiled a list for you to have a look and learn, It will be helpful to you in this task as well as in future endeavours.

About grid's RowDataBound event, usage, examples and best of all source code!
http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/GridViewClassRowDataBound.aspx

All asp.net Getting Started tutorials here:
http://authors.aspalliance.com/aspxtreme/aspnet/index.aspx

How to use String object:
http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithStringsP311232005021723AM/WorkingWithStringsP3.aspx

Let me know if you have doubt as how to proceed
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 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