Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-22
4
Medium Priority
?
1,331 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

963 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