Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Datalist

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have a nested datalist within another datalist but can't seem to get it working.

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"
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top