I have an xml documents that I need to bind using a repeater. This is to be a "preview" of a few rows of data with a "view more" link to see them all. Is it possible to do this using just one xml document? the xml file has about 15 items, but I only want to bind the first 4 or 5. Can this be done declaratively or do I have to make a new document that is a subset of the original and bind to that? seems pretty wasteful, but I cannot for the life of me find a way to stop databinding after X rows on any of the data controls!

any ideas? thanks!

well I ended up cheating and using a gridview control. I set the paging to true with a pagesize of 5 and then made the pager invisible.

I know it's not ideal because 1) gridview renders a table, and I wanted a list and of course 2) GridView is clientside paging, meaning it read all of the data instead of the first X rows and stopping...

BUT, it works, for now, until I find a more efficient solution. suggestions are still appreciated!

thanks

Comments
Good to see a poster post their solution so others may benefit

thank you for the link. I am actually pretty familiar with the repeater controls and how to use them, but this is a special operation that I've not seen done before.

I do want to bind to a list but what I want to do is STOP binding after say 5 rows.

It seems like it would be more logical to just limit the data retrieved from the xml file. I know how to do this with a dataview if the data was coming from a dataset or database, but i'm using the xmldatasource which is a text file. I'm thinking I'd have to make my own class to bind to by reading the xml node by node until I hit the limit.

unless anyone else has any ideas! thanks

Hmm I guess you could do what you originally intended and make a new file that is a subset of the original with the 5 or so items you wish to bind. although I understand your concern about this as it does seem somewhat un-elegant. Let me know your thoughts on this...

well I think loading the whole thing into memory and cheating with the paging is doing the trick for now. the list is thankfully not so long that loading the whole thing into memory for just a few rows will be overtaxing resources. if I ever find a better way I'll report back.

if anyone else ever has an idea, please do the same :)

OK sorry that i could not help more, not had much experience with using xml datasources. Maybe someone with more will reply.

This article has been dead for over six months. Start a new discussion instead.