Access child element in nested repeaters (ASP.NET/C#)
Posted on 2004-09-21
I have a page displaying bookmarks stored in a database, and organised in categories. The output has this form:
I am displaying a checkbox next to each bookmark, and at the bottom of the list I have a delete button that should delete the bookmarks that have been checked by the user. The bookmarks and the categories are displayed using nested repeaters (where, naturally, the bookmarks are the child elements). When the button is clicked, it triggers an event that loops through the elements in the repeater, but I cant get it to loop through the child elements - only the parent (categories). The below code works fine for the parent elements (by using "parentrepeater" instead of "childrepeater")
for (int i = 0; i < childrepeater.Items.Count; i++) // error comes here - childrepeater seems to be unaccessible
CheckBox CurrentCheckBox = new CheckBox();
CurrentCheckBox = (CheckBox) childrepeater.Items[i].FindControl("Checkbox1");
// delete bookmark
But even though this code compiles, I get "Object reference not set to an instance of an object". The childrepeater is not initialised/instansiated, even though it's drawn on screen.
Anyone have an idea here? How do I access child elements in nested repeaters?