Limiting a Datalist

Discussion in 'ASP.NET 2.0' started by kkarasin, Jun 25, 2006.

  1. Couldn't you just say SELECT TOP 5 in your sql statment


    for example

    SELECT TOP 5 PowerPlants.* FROM PowerPlants, States WHERE

    (States.Name = 'California' Or States.Name = 'Nevada') AND

    Contains(States.ID, PowerPlants.ID) ORDER BY PowerPlants.Power;




    This selects the 5 largest power plants in California and Nevada.
     
  2. Wow, that was easier than I thought. Thank You!!!

    I have also be trying tofigure outhow to limit the number of characters displayed from a certain column. For instance, the "message" column contains up to 1000 characters but I only want the first 50 to display. Is this as simple as the other solution?

    I really need to do more studying.

    Thanks again,
    Rookie
     
  3. If your talking sql you can use the substring function

    Syntax
    SUBSTRING ( expression , start , length )
    like this




    USE pubs
    SELECT pub_id, SUBSTRING(logo, 1, 10) AS logo,
    SUBSTRING(pr_info, 1, 10) AS pr_info
    FROM pub_info
    WHERE pub_id = '1756'

    Here is the result set:

    pub_id logo pr_info
    ------ ---------------------- ----------
    1756 0x474946383961E3002500 This is sa

    (1 row(s) affected)



    Here is all you you ever wanted to know about subsring

    msdn.microsoft.com/library/?url=/library/en-us/tsqlref/ts_setu-sus_6btz.asp
     
  4. Thank you very much!


    I'll be sure to start reading.
     
  5. I'm using VS 2005 and I am trying to make a datalist display the five latest messages submitted in the database. I've looked for way to do this out of the box but can't seem to find anything. Does anyone know of an easy way to do this?

    I'm just learning C# so unfortunately I can't rely on my coding skills yet to create this myself.

    Any help would be great.

    Thanks,
    rookie
     

Share This Page