Solved

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

Posted on 2008-10-22
4
1,295 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
ID: 22779389
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
ID: 22779445
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

17 Experts available now in Live!

Get 1:1 Help Now