如何数据绑定三级嵌套中继器

时间:2011-12-15 12:49:09

标签: asp.net

我有三个嵌套的中继器,我有数据绑定的第一个和第二个,但我无法弄清楚如何数据绑定第三个我的这里是我的标记:

<asp:Repeater ID="mainMenuRepeater" runat="server">
            <HeaderTemplate><ul></HeaderTemplate>
            <ItemTemplate>

            <li><a title='<%#Eval("post_name")%>' id='<%#Eval("id")%>'  href='<%#ResolveUrl(Eval("post_permalink"))%>'><%# Eval("post_name")%></a>
                <asp:Repeater ID="subMenuRepeater" runat="server">
                <HeaderTemplate><ul></HeaderTemplate>
                <ItemTemplate>

                 <li>
                 <a href='<%#ResolveUrl(Eval("post_permalink"))%>'><%# Eval("post_name")%></a>

                     <asp:Repeater ID="sub_subMenuRepeater" runat="server">
                      <HeaderTemplate><ul></HeaderTemplate>
                        <ItemTemplate>
                        <li><a href='<%#ResolveUrl(Eval("post_permalink"))%>'><%# Eval("post_name")%></a></li>
                      </ItemTemplate>
                      <FooterTemplate></ul></FooterTemplate>
                     </asp:Repeater>
                 </li>

                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
                </asp:Repeater>
            </li>
            </ItemTemplate>
            <FooterTemplate></li>
            <br style="clear: left" />
            </FooterTemplate>
            </asp:Repeater>

以下是我的代码,用于编写第二个名为subMenuRepeater的转发器:

Protected Sub mainMenuRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles mainMenuRepeater.ItemDataBound
        Try
            If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

                'Dim dv As DataRowView = CType(e.Item.DataItem, DataRowView)
                Dim ad As Int32 = CType(DataBinder.Eval(e.Item.DataItem, "id").ToString(), Int32)
                Dim db As iwebmalldatacontextDataContext = New iwebmalldatacontextDataContext()
                Dim menus = From m In db.iwebmall_posts
                            Where m.post_type = "page" And m.post_status = 1 And m.post_parent = ad Order By m.post_menu_order
                            Select m.post_permalink, m.post_name, m.id

                Dim subMenu As Repeater = CType(e.Item.FindControl("subMenuRepeater"), Repeater)
                If menus.Count > 0 Then
                    With subMenu
                        .DataSource = menus
                        .DataBind()
                    End With
                End If

            End If




        Catch ex As Exception
            '  Throw ex
        End Try
    End Sub

请问如何在命名的sub_subMenuRepeater上对第三个进行数据绑定。提前致谢

1 个答案:

答案 0 :(得分:0)

您可以重复与第一个嵌套转发器相同的过程。

当调用外部转发器的ItemDataBound事件时,您将获取当前Item,然后绑定嵌套转发器的属性。

如果您订阅嵌套转发器的ItemDataBound事件,则可以对subnested转发器进行数据绑定。