Solved

Limit text in asp:Label text=" " to just 100 characters

Posted on 2008-10-22
4
1,285 Views
Last Modified: 2012-05-05
I am finishing up the development of a web site in ASP.NET with VB.NET and MS SQL Server 2005 on MS Visual Web Developer.  I have a query which pulls the record for a specified product from the table, returning the description field (varchar(6000)).  On my web page, I want to display just the first 100 characters of the description, followed by an elipse (...).  I'm out of time on this project so would like some help, please.
Dim myConn2 As New SqlConnection(ConfigurationManager.ConnectionStrings("omahavaccineConnectionString").ToString)

        myCmd2.Connection = myConn2

        myCmd2.CommandType = CommandType.Text

        myCmd2.CommandText = "Select * from Product where sku='" & strSKU & "' "

        myConn2.Open()

        Dim myReader2 As SqlDataReader = myCmd2.ExecuteReader()

        Do While myReader2.Read

            lblshort_description = (TRIM(myReader2("description")),100) & " ..."

        Loop

        myConn2.Close()

Open in new window

0
Comment
Question by:OVC-it-guy
4 Comments
 
LVL 7

Accepted Solution

by:
the_bachelor earned 500 total points
Comment Utility
you could do this on the database level
SELECT *, CASE 

	WHEN LEN([Description]) <=100 THEN [Description]

	ELSE SUBSTRING([Description], 1,100) + '(...)'

END AS ShortDescription FROM Product where ...

Open in new window

0
 

Author Comment

by:OVC-it-guy
Comment Utility
Ooh, I like that better than what I was thinking.  Why return all that extraneous text when I only need about 100 characters?!?  I'll give that a try!
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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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.…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now