开发者

How to add a RepeaterItem to an asp:Repeater using the Controls() method

开发者 https://www.devze.com 2023-04-11 04:17 出处:网络
I have declared an asp:Repeater on my page with ID=\"AnswersRepeater\". I am calling the below segment of code when the user clicks a button on the page to load additional data from a DataSet denoted

I have declared an asp:Repeater on my page with ID="AnswersRepeater". I am calling the below segment of code when the user clicks a button on the page to load additional data from a DataSet denoted as "ds". I need to understand the control hierarchy of an asp:repeater so I can add back in the items the repeater had after rebinding to the datasource like below:

Dim cur开发者_JAVA百科rentItems As New ArrayList(AnswersRepeater.Items)
AnswersRepeater.DataSource = ds
AnswersRepeater.DataBind()
For Each item As RepeaterItem In currentItems
   AnswersRepeater.Controls.Add(item)
Next

The problem is, the RepeaterItems are not added in the correct place within the repeater control's hierarchy. I need to find the item template and append the items in currentItems array to it. Any help is much appreciated.


You shouldn't be directly editing the controls of the Repeater control, the idea is you bind to a data source and it dynamically creates controls for you based on that data source.

You'd be better adding the items you already have to your data source ds and then just binding once.

0

精彩评论

暂无评论...
验证码 换一张
取 消