Solved

asp.net gridview string length

Posted on 2008-10-30
7
721 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

13 Experts available now in Live!

Get 1:1 Help Now