Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Displaying description field with only a few lines and a "read more"... at the end

    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?

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    in your sql to retrieve the data you could have something like

    select column1,
    , coumn2
    .....etc.
    ,SUBSTR(YourDescription,1,N) || '...' as Descr
    from yourtable
    where .....

    the link would just contain the ID needed to pull that row(s)
    from the database. Maybe use an item template?

    fv

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile SQL statement question...

    Thanks FractalVibes...
    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?

    Thanks!
    -WebGal77

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Good Luck,

    fv


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •