Solved

asp.net gridview string length

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 34
SQL Server Data Tools for Visual Studio 2015 - backward compatibility. 2 87
error on the asp.net page 1 33
Advice in Xamarin 21 57
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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.…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

895 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

14 Experts available now in Live!

Get 1:1 Help Now