0

I can use nested repeater to show my grouped data on a page (according to this: http://goo.gl/sH6g). In my case I have Category-Products structure and want to show each category and its products under it.

But here are my problems:

  1. How can I limit number of products showing under each category. I want to determine for example 5 newest products for each category?
  2. How can I conditionally limit the number of products. For example I want to determine if there is no subcategory for a specific category show all products else show 5 newest products?
  3. Is repeater suitable for that work? if NOT which data control should I use?

Please give me some guidelines!.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
Mehdi
  • 5,435
  • 6
  • 37
  • 57

1 Answers1

1

You can limit the amount of records from your SQL statements.

For example, you can use SELECT TOP like this

SELECT TOP 5 * FROM Products Where CategoryId = 1

You can also use LIMIT

SELECT * FROM Products Where CategoryId = 1
LIMIT 5

Or for LINQ - see this post LinqDataSource - Can you limit the amount of records returned?

Community
  • 1
  • 1
Marko
  • 71,361
  • 28
  • 124
  • 158
  • you know I used LinqDataSource and DBML. – Mehdi Jul 04 '10 at 15:16
  • Check this answer out http://stackoverflow.com/questions/4221/linqdatasource-can-you-limit-the-amount-of-records-returned – Marko Jul 04 '10 at 20:58
  • I've included the link in the answer as well. There's no reason to limit from the Repeater since your DS will still be selecting all the records. If you still can't get it to work, I'll write you a c# solution :) Good luck – Marko Jul 04 '10 at 21:00