Inside this, I have another repeat...">

Access to a nested repeater data source

I have a repeater:

<asp:Repeater ID="rptSessions" runat="server">

Inside this, I have another repeater:

 <asp:Repeater ID="rptPeople" runat="server" OnItemDataBound="rptPeople_ItemDataBound"> 

In ItemDataBound on my parent repeater, I set the data source for the child repeater.

  Dim dtPeople As New DataTable dtPeople.Columns.Add("FirstName") dtPeople.Columns.Add("LastName") dtPeople.Columns.Add("Company") If e.Item.DataItem("Lunch") = True Then dtPeople.Columns.Add("Dietary") <-- *** rptPeople.DataSource = dtPeople rptPeople.DataBind() 

Now consider html for my child repeater

 <asp:Repeater ID="rptPeople" runat="server" OnItemDataBound="rptPeople_ItemDataBound"> <HeaderTemplate> <table> <tr> <th>First Name</th> <th>Last Name</th> <th>Company</th> <asp:Literal ID="litDietaryRequirements" runat="server"><th>Dietary Requirements</th></asp:Literal> </tr> </HeaderTemplate> ..... 

In the ItemDataBound for my child relay, I would like to hide litDietaryRequirements depending on whether the Dietary column in it has a datasource in it. I tried the following:

 If e.Item.ItemType = ListItemType.Header Then DirectCast(e.Item.FindControl("litDietaryRequirements"), Literal).Visible = DirectCast(e.Item.DataItem, DataRowView).Row.Table.Columns.Contains("Lunch") End If 

e.Item.DataItem seems Nothing

+1
source share
1 answer

I finally did this:

 If e.Item.ItemType = ListItemType.Header Then Dim LunchRequired As Boolean = DirectCast(DirectCast(e.Item.NamingContainer.NamingContainer, RepeaterItem).DataItem, DataRowView).Row.Item("Lunch") DirectCast(e.Item.FindControl("litDietaryRequirements"), Literal).Visible = LunchRequired End If 
0
source

All Articles