I have a nested datalist within another datalist but can't seem to get it working.
Here is my datalist code:
My code behind:
The nested datalist does not populate correctly. It will If I change the line
to
but then it shows the same nested info for each parent record. Or any other number.
There are 12 records in the parent table. If I remove 11 of them and just have 1 record it works.
I have added the Response.Write(CategoryID) to test to see it is retrieving the correct information and it does seem to retrieve all the CategoryID - 1234567891011 as an array.
Any ideas?
Here is my datalist code:
Code:
<asp:DataList ID="dlCategories" runat="server" DataKeyField="AwardCategoryID"
DataSourceID="GetCategories" OnItemDataBound="loaditems">
<ItemTemplate>
<br />
<br />
<h4><asp:Label ID="AwardCategoryIDLabel" runat="server"
Text='<%# Eval("AwardCategoryID") %>' /></h4>
<h4><asp:Label ID="AwardCategoryLabel" runat="server"
Text='<%# Eval("AwardCategory") %>' /></h4>
<asp:Label ID="IntroLabel" runat="server" Text='<%# Eval("Intro") %>' CssClass="categoryintro" />
<br />
<asp:Label ID="DescriptionLabel" runat="server" CssClass="bodytext"
Text='<%# Eval("Description") %>' />
<br />
<br />
Criteria:
<asp:DataList ID="dlCriteria" runat="server" DataKeyField="AwardCriteriaID"
DataSourceID="GetCriteria">
<ItemTemplate>
<asp:Label ID="AwardCriteriaIDLabel" runat="server"
Text='<%# Eval("AwardCriteriaID") %>' Visible="false" />
<asp:Label ID="AwardCategoryLabel" runat="server"
Text='<%# Eval("AwardCategory") %>' Visible="false" />
<asp:Label ID="CriteriaLabel" runat="server" Text='<%# Eval("Criteria") %>' />
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
My code behind:
Code:
Protected Sub loaditems(ByVal sender As Object, ByVal e As DataListItemEventArgs)
If (e.Item.ItemType = ListItemType.Item Or ListItemType.AlternatingItem) Then
Dim CategoryID As String = DirectCast(e.Item.FindControl("AwardCategoryIDLabel"), Label).Text
Dim CriteriaList As DataList = CType(e.Item.FindControl("dlCriteria"), DataList)
Response.Write(CategoryID)
Me.GetCriteria.SelectParameters("AwardCategory").DefaultValue = CategoryID
CriteriaList.DataSourceID = GetCriteria.ID
End If
End Sub
The nested datalist does not populate correctly. It will If I change the line
Code:
Me.GetCriteria.SelectParameters("AwardCategory").DefaultValue = CategoryID
to
Code:
Me.GetCriteria.SelectParameters("AwardCategory").DefaultValue = "1"
There are 12 records in the parent table. If I remove 11 of them and just have 1 record it works.
I have added the Response.Write(CategoryID) to test to see it is retrieving the correct information and it does seem to retrieve all the CategoryID - 1234567891011 as an array.
Any ideas?