?
Solved

asp.net gridview string length

Posted on 2008-10-30
7
Medium Priority
?
728 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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