Monday, March 26, 2012

Updating Nested Repeaters

I'm working on a page with nested repeaters. The child repeater is for comments that can be added by users. My problem is updating the child repeater when a comment is added. I have something like:

<UpdatePanel id="parentUpdatePanel">

<repeater id="parent">

<item stuff>

<UpdatePanel id="commentUpdatePanel">

<repeater id="comments">

<comment stuff>

</repeater>

<a href="http://links.10026.com/?link=javascript:AddComment(itemID)">Add Comment</a>

</UpdatePanel>

</repeater>

</UpdatePanel>

The AddComment function brings up a div-type-dialog to enter the comment. It's doing an AJAX postback to add the comment, but I can't find a way to get back to my comment repeater to update it with the added comment. The comments are also in an asp:panel, so that I can hide them until the user clicks on a "View Comments" link under each item. I could possibly just collapse the panel, and when they re-expand it, it will reload just fine, but that won't look very nice.

I assume that when the parent repeater is databound you are also binding the child repeater for each item in the parent repeater, am I correct? If this is the case if you were to call databind again for your parent repeater shouldn't this rebind the child comment repeater within?


I've found a way around my issue. I tacked on a hidden field in my parent repeater with the item's ID value so I can do a FindControl on the hidden field and match the item ID up. Then, if I know which item I'm dealing with in the parent I can also do a FindControl on my child repeater and update it. Less elegant than I'd like, but it works quite well.

No comments:

Post a Comment