嵌套的Repeater Asp .NET ItemDataBound没有被调用?

时间:2013-08-21 12:29:36

标签: asp.net asprepeater itemdatabound

我正试图筑巢2个中继器。第二个转发器是第一个转发器的itemDataBind事件的数据绑定。

<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>

第一个转发器绑定在PageLoad上,第二个转发器绑定在第一个转发器的项数据绑定事件上。但是,似乎没有调用我的ItemDataBound事件,因为没有显示第二个转发器项目。

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

这将是itemDataBound事件。 response.write(“test”)中的文字没有显示在我的网页上,所以我怀疑它从未被调用过?

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 个答案:

答案 0 :(得分:0)

问题在于:

FolderRepeater.Dispose()

似乎dispose禁用未来事件?无论如何,现在我评论它是有效的。

答案 1 :(得分:0)

你已经在这里找到了问题,这很好:

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

如果这不是输入错误,您应该仔细阅读正确使用Dispose()功能。当您搜索网络时,有很多相关信息,例如: