views:

1599

answers:

2

Hi there,

I have already created a webpart to show the data from list, but I really want is to only show top 5 records from that list (by using CAML query).

Does anyone know how to do this? Many thanks.

<Query>
   <OrderBy>
      <FieldRef Name='ID' Ascending='False' />
   </OrderBy>
</Query>
+6  A: 

You could set the RowLimit property of your SPQuery object.

The <RowLimit> tag is in the schema definition of a view (direct child of <View>) and therefore cannot be nested inside a <Query> tag.

Tudor Olariu
Thank you very much. It works.
Daoming Yang
A: 

The below code shows top 5 records from the list (by using CAML query).

SPQuery spQuery = new SPQuery(); spQuery.Query = ""; spQuery.RowLimit = 5;

Sunil Kumar Pashikanti