I have a nested repeater control. Here is what the HTML looks like:
<ItemTemplate>
<div class="boxLeft">
<h4><%# DataBinder.Eval(Container.DataItem, "DisciplineName") %></h4><asp:Label runat="server" ID="lblDisciplineID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "DisciplineID") %>'></asp:Label>
<p><%# DataBinder.Eval(Container.DataItem, "DisciplineNarrative") %></p>
<h5 class="articles"><%# DataBinder.Eval(Container.DataItem, "InstructorCount")%> instructors</h5>
<ul>
<asp:Repeater runat="server" ID="rptRegions">
<ItemTemplate>
<li><a href='/Lessons/<%# DataBinder.Eval(Container.DataItem, "DisciplineName") %>/<%# DataBinder.Eval(Container.DataItem, "CityName") %>'><%# DataBinder.Eval(Container.DataItem, "CityName") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</ItemTemplate>
As you can see, I want to access the parent DisciplineName property from the parent repeater, in my child repeater in order to build the URL. I get the following error:
DataBinding: ‘GolfLessonSearch.Model.CityEntity’ does not contain a
property with the name ‘DisciplineName’.
This is because it is trying to get “DisciplineName” from the child repeater but I want it from the parent repeater. I thought that the properties may still be in scope but it appears not. Is there any way of getting this?
If the objects behind your DataItems have the same parent/child relationship as you are trying to represent them in the repeater, you can always fully qualify the property name so that your child repeater is calling
If this isn’t the case, my gut would be to create a ViewModel object (even though it’s not mvc) of your child object to fake that relationship…
EDIT
Just a note that when I said “Parent.DisciplineName”, I meant to replace “Parent” with the object name… (I only qualify because “Parent” is a reserved word in so many other places in asp.net…