View Full Version : Displaying description field with only a few lines and a "read more"... at the end
01-07-2005, 11:36 PM
I am sort of new to ASP.net but have been able to get whatever answers I need from sample code. But I'm finally stuck. I have a small DB and search engine that is displaying different restaurants in a Datalist. When the list is generated I want the description field to only display like two or three lines underneath the name with a "..READ MORE...." type link at the end that will open up the detail.aspx page I have. The description is just a regular Access table field.... but I don't want it to display the entire content of the field... Any ideas?
01-07-2005, 11:59 PM
in your sql to retrieve the data you could have something like
,SUBSTR(YourDescription,1,N) || '...' as Descr
the link would just contain the ID needed to pull that row(s)
from the database. Maybe use an item template?
01-08-2005, 07:10 PM
I figured it would be in the SQL statement.... but I am still getting an error with the double bar || ? Maybe I am taking what you suggested too literally (I am an SQL amateur also) but this is what I had:
Dim sql as string = "Select TextToDisplay, SUBSTR(TEXTTODISPLAY,1,N) || '...' as Descr from Restaurants where DisplayLive = 'yes' "
what it the SUBSTR(TEXTTODISPLAY,1,N) part mean also?
01-08-2005, 10:54 PM
say you have a database table named restaurants with the following columns; Rest_Name, Rest_location, Menu_description
now say you want to display this information on a website but dont want people knowing the headings of the columns for whatever reason. You can write a sql statement to change the name of the heading
SELECT Rest_Name AS Restaurant, Rest_location AS Location, Menu_Description As [Menu Description] FROM restaurants
This will change the column headings of all fields when displayed.
Now the SubString(TextToDisplay,1,n) will say to start from the 1st character in the string, TextToDisplay and go to only the nth character then stop.
01-09-2005, 06:46 AM
The double bar || is SQL standard concatenation function. I think that there is also a CONCAT(string1,string2) function.
The SUBSTR(YourColumnHere,1,N) means to just grab the charactors in whatever char column you want and return the portion beginning at the first charactor, and all columns up to the Nth column. For example, if you just wanted to display the first 30 charactors from the description as a teaser, you would do:
SUBSTR(Description,1,30) as MyAbbreviatedDescription
I don't know what type database you are using, and there certainly are some differences between them. Do a google search on DB2 Cookbook - some things are Db2-specific, but it does have some nice examples of standard SQL also.
Get a good book on SQL - you'll be suprised at how much you can do with it! Really a lot of stuff that you might think you'd have to write in ASP or some other language.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.