Nested Repeaters Asp .NET ItemDataBound not called?

1.4k views Asked by At

I am trying to nest 2 repeaters. 2nd repeater is data bound on first repeater's itemDataBind event.

<asp:Repeater ID="FolderRepeater" runat="server" OnItemDataBound="CategoryRepeater_ItemDataBound">
<ItemTemplate>
    <p><%# Container.DataItem("DocumentName")%></p>
    <asp:Repeater ID="someRepeater" runat="server">
        <ItemTemplate>
            <p>TEST<%# Container.DataItem("NodeAlias")%></p></br>
        </ItemTemplate>
    </asp:Repeater>
</ItemTemplate>

First repeater is bound on PageLoad, and second repeater is bound on 1st repeater's item data bound event. However, it seems like my ItemDataBound event is not called, as 2nd repeater items are not being displayed.

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim datasetFolders As New DataSet()

    Dim da As SqlDataAdapter = New SqlDataAdapter()
    Dim sqlQry As String
    Dim conn As New SqlConnection(CMS.DataEngine.SqlHelper.ConnectionString)

    sqlQry = "SELECT * FROM dbo.CMS_Document WHERE DocumentNamePath LIKE '/Galerie/%' AND DocumentExtensions IS NULL"

    da.SelectCommand = New SqlCommand(sqlQry, conn)
    conn.Open()
    da.Fill(datasetFolders)
    conn.Close()

    FolderRepeater.Dispose()
    FolderRepeater.DataSource = datasetFolders
    FolderRepeater.DataBind()
End Sub

and this would be the itemDataBound event. Text in response.write("test") is not displayed on my webpage, so I suspect its never called?

Protected Sub CategoryRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles FolderRepeater.ItemDataBound
    Response.Write("test")

    Dim item As RepeaterItem
    item = e.Item

    Dim imageFolder As New DataSet

    Dim da As SqlDataAdapter = New SqlDataAdapter()
    Dim sqlQry As String
    Dim conn As New SqlConnection(CMS.DataEngine.SqlHelper.ConnectionString)

    sqlQry = "SELECT * FROM dbo.View_CONTENT_File_Joined WHERE NodeAliasPath LIKE '/Galerie/" & e.Item.DataItem("DocumentName") & "/%'"

    da.SelectCommand = New SqlCommand(sqlQry, conn)
    conn.Open()
    da.Fill(imageFolder)
    conn.Close()

    Dim someRepeater As Repeater
    someRepeater = e.Item.FindControl("someRepeater")
    someRepeater.DataSource = imageFolder
    someRepeater.DataBind()
End Sub
2

There are 2 answers

0
lucafik On

Problem was with this:

FolderRepeater.Dispose()

It seems like dispose disables future events? Anyway, now that I commented it out it works.

0
w5l On

It's good that you already found the problem here:

FolderRepeater.Dispose()
FolderRepeater.DataSource = datasetFolders
FolderRepeater.DataBind()

If this was not a typing mistake, you should really read up on the proper use of the Dispose() function. There is plenty of information about this when you search the web, ie.: