tags:

views:

56

answers:

2

i have a asp.net repeater control .I have to display only two rows in the repeater .but my dataset has 10 rows ..is there a way to restrict the number of rows of a repater ?

+1  A: 

I would Take the appropriate number of rows from your original DataSet

I don't have my IDE in front of me, but the idea is something like

Repeater1.DataSource = MyDataSet.Take(2).ToList();

Alternatively if you need to sort it, you could try something like this

Repeater1.DataSource = (from ds in MyDataSet
                        select ds
                        orderby SomeValue descending).Take(2); 

You can also skip the first X rows and then return 2

Repeater1.DataSource = MyDataSet.Skip(20).Take(2).ToList();
rockinthesixstring
@rockinthesixstring - hehe, nice work copying my comment. you thief! :)
RPM1984
sorry didn't see the comment. I just thought about it after I made my original post. NOTE: all credit to the first option be to RPM :-p
rockinthesixstring
no probs, i'm just winding you up anyway. :)
RPM1984
also, sorry for hacking this together.. I keep having to go back to the code converter since I'm a VB guy :(
rockinthesixstring
A: 

You can also use the PagedDataSource class, this class encapsulates the paging related properties of a data-bound control.

vinayak