4

我认为简短的回答是你不能,但必须有某种方式来实现它。我想制作一个项目列表,然后在其中有一个项目列表,只嵌套一个级别。IE:

 Repeater  
    UserControl1  
        UserControl1  
        UserControl1  
    UserControl1
        UserControl1  
    UserControl1  
    UserControl1  

如果可能的话,我真的很想避免使用 LoadControl,因为我在服务器端 Click 事件中添加了这个列表,所以我不能在 PageInit 上执行 loadControl 来让所有视图状态的东西工作。

我将尝试编写一个快速的伪代码示例,它看起来像这样:

页面.aspx

<asp:repeater runat="Server" id="someRepeater">
<uc:UserControl1 runat="Server" id="ctrlParent" />
</asp:repeater>

用户控件1.ascx

<asp:label id="label1" runat="server" />
<asp:repeater runat="server" id="childRepeater">
    <uc:UserControl1 runat="server" id="ctrlChild" />
</asp:repeater>

用户控件1.ascx.vb

If me.HasChildren then
    'BindChildRepeater'
end if

sub Fill(Data as RelevantData)
    label1.Text = Data.SomeText
end sub

sub ChildRepeater_ItemDataBound(object as sender, e as someArgs)
    Dim childCtrl = e.item.findcontrol("ctrlChild")
    childCtrl.Fill(e.item.dataitem)
end sub
4

3 回答 3

2

您可以在中继器中嵌套中继器

<asp:repeater runat="Server" id="someRepeater1">
    <uc:UserControl1 runat="Server" id="ctrlParent1" />
    <asp:repeater runat="Server" id="someRepeater2">
        <uc:UserControl1 runat="Server" id="ctrlParent2" />
    </asp:repeater>
</asp:repeater>
于 2012-06-13T20:02:15.673 回答
0

只需<%@ Register src="" tagname="" tagprefix=""%>在要调用另一个用户控件的用户控件中调用 .. 在另一个用户控件中调用用户控件与在普通 aspx 页面中调用用户控件相同。

于 2012-06-13T19:59:37.893 回答
0

这就是我所做的。基本上,您使用 LoadControl 添加的控件将在回发后消失,所以我所做的只是在回发期间调用此函数Page_Load

Private Sub AddSubCategorizedQuestionItemControls()

    If rptSubCategorizedquestionList.Items IsNot Nothing AndAlso
        rptSubCategorizedquestionList.Items.Count > 0 Then

        For Each _item As RepeaterItem In rptSubCategorizedquestionList.Items

            If _item.ItemType = ListItemType.AlternatingItem OrElse
                     _item.ItemType = ListItemType.Item Then

                Dim _hfCategoryID As HiddenField = _item.FindControl("hfCategoryID")

                Dim _placeHolderSubCategoryQuestionItem As PlaceHolder = _item.FindControl("placeHolderSubCategoryQuestionItem")

                Dim _nestedCategorizedListItemControlUserControlObject As UserControl =
                                                                LoadControl("__categorizedQuestionListItem.ascx")

                _nestedCategorizedListItemControlUserControlObject.ID =
                                      String.Format("ucCategorizedQuestionListItem", _hfCategoryID.Value)

                _placeHolderSubCategoryQuestionItem.Controls.Add(_nestedCategorizedListItemControlUserControlObject)

                Dim _nestedCategorizedListItem As Common_Questions__categorizedQuestionListItem =
                    DirectCast(_nestedCategorizedListItemControlUserControlObject, Common_Questions__categorizedQuestionListItem)

            End If

        Next

    End If

End Sub
于 2014-08-20T19:57:16.587 回答