views:

4006

answers:

4

I have a .NET repeater control that is data-bound to a List. As part of the Repeater's ItemCollection, I have a "Remove Button" that effectively removes this current List element.

This works, in code-behind I can successfully remove an item from the datasource of the Repeater.

My problem is this : when I reset the updated datasource and call MyRepeater.DataBind() again, the Repeater interface does not refresh with the Item removed.

I am looking for the event to essentially redraw or refresh the Repeater based on the updated List. Thanks for any pointers or examples.

+1  A: 

Are you feeding the refreshed data source?

If you are setting data source in code-behind, you need to set it with refreshed data then call DataBind method.

Brian Kim
Yes. I am refreshing the datasource and immediately calling the DataBind method.
Ash Machine
Hmm... Maybe you can post some of your code.
Brian Kim
A: 

Forcing Databind is normally done where the automatic DataBind is done in the PreRender event.

Normally if you did the remove in the click event, the repeater should refresh by itself since automatically in the preRender, controls on page are DataBind(). Here is what the doc of microsoft say :

PreRender : Before this event occurs each data bound control whose DataSourceID property is set calls its DataBind method.

source

So probably you affected Youritem.DataSource = List, but MS suggest doing YourItem.DataSourceID = List.ID, or something like that.

Hope it helps

lucian.jp
+2  A: 

You need to call the 'DataBind' method on your datasource, then call 'DataBind' on your Repeater control.

David HAust
A: 

I had a similar situation...a repeater bound to an xmlDataSource, both inside an UpdatePanel. I wanted to let the user type in one name at a time then click an "Add" button to update the list in the repeater.

I set "EnableViewState" to False on the repeater and the xmlDataSource, and set "EnableCaching" on the xmlDataSource to False as well. I set the Data property of the xmlDataSource, called DataBind for the xmlDataSource, set the DataSourceID property of the repeater, then called DataBind for the repeater. Maybe that was overkill...but it worked. Maybe this will help.

UPDATE: I found that by setting EnableViewState to False on the repeater control, my ItemCommand event would not fire. But I think you only need to set EnableViewState/EnableCaching to False for the data source...I have returned the EnableViewState setting to True for the repeater and now all seems well.