本文介绍了如何绑定内中继?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还有一个中继器内的中继器。现在我想的内部Repeater绑定。但我m到处的错误不设置到对象的实例对象引用。我的code是

 保护小组rep_test_ItemDataBound(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.RepeaterItemEventArgs)处理rep_test.ItemDataBound
    昏暗DT作为新的DataTable
    DT = obj.getdata()
    昏暗innerRepeater由于直放站= DirectCast(e.Item.FindControl(innerRepeater),中继器)
    innerRepeater.DataSource = DT
    innerRepeater.DataBind()
结束小组

我的源$ C ​​$ c是

 < ASP:直放站ID =rep_test=服务器>
        <&ItemTemplate中GT;
            < D​​IV ID ='H<%#DataBinder.Eval的(集装箱的ItemIndex)%>'类=头的onclick ='ToggleDisplay(小于%#DataBinder.Eval的(容器的ItemIndex)%&GT);'>
                <%#DataBinder.Eval的(的Container.DataItem,ID)%GT;
            < / DIV>
            < D​​IV ID ='D<%#DataBinder.Eval的(集装箱的ItemIndex)%>'类=细节>
            < ASP:直放站ID =rep_hello=服务器>
            <&ItemTemplate中GT;
                <%#DataBinder.Eval的(的Container.DataItem,batchid)%>< BR />
                <%#DataBinder.Eval的(的Container.DataItem,TS)%GT;< BR />
            < / ItemTemplate中>
            < / ASP:直放站>
            <% - <%#DataBinder.Eval的(的Container.DataItem,batchid)%>< BR />
                <%#DataBinder.Eval的(的Container.DataItem,TS)%GT;< BR /> - %GT;
            < / DIV>
        < / ItemTemplate中>
    < / ASP:直放站>


解决方案

如果您在父中继器的页眉或页脚,你的方法可能是他们过于执行,因此没有找到内部控制。

尝试检查 e.Item.ItemType 是只为 ListItemType.Item ListItemType.AlternatingItem ,只执行你的code在这种情况下。

当然不能保证,如果这就是问题所在。还检查确认中继器ID是否正确,并验证它的直接父中继器的项目模板中,而不是里面的项目内的另一个服务器控件(或者,你需要先找到其他控制,然后找到里面中继器)。

另外,还要确保你正在使用 rep_hello ID不是 innerRepeater

&BTW LT;你可以在标记这样做太...

 < ASP:直放站=服务器ID =innerRepeater
    数据源='<%#的eval(PropertyInParentObject)%>' >
    ....
    ....
< / ASP:直放站>

您可以使用的Container.DataItem 而不是评估太(并把它转换为在类型的对象父直放站项目)。

i have a repeater inside another repeater. now i want to bind the inner repeater. but i m getting error of "Object reference not set to an instance of an object.". my code is

Protected Sub rep_test_ItemDataBound(ByVal sender As Object, ByVal e As   System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rep_test.ItemDataBound
    Dim dt As New DataTable
    dt = obj.getdata()
    Dim innerRepeater As Repeater = DirectCast(e.Item.FindControl("innerRepeater"), Repeater)
    innerRepeater.DataSource = dt
    innerRepeater.DataBind()
End Sub

my source code is

<asp:Repeater ID="rep_test" runat="server">
        <ItemTemplate>
            <div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header" onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);'>
                <%#DataBinder.Eval(Container.DataItem, "ID")%>
            </div>
            <div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
            <asp:Repeater ID="rep_hello" runat="server">
            <ItemTemplate>
                <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                <%#DataBinder.Eval(Container.DataItem, "ts")%><br />
            </ItemTemplate>
            </asp:Repeater>
            <%--    <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                <%#DataBinder.Eval(Container.DataItem, "ts")%><br />--%>
            </div>
        </ItemTemplate>
    </asp:Repeater>
解决方案

If you have a header or footer in the parent repeater, your method might be executed for them too, and hence not finding the inner control.

Try to check if the e.Item.ItemType is "only" either ListItemType.Item or ListItemType.AlternatingItem, and only execute your code in this case.

Of course can't guarantee if this is the problem. Check also for confirming that repeater ID is correct, and verify that it's directly inside the item template of the parent repeater, not inside another server control inside the item (or else, you'll need to find the other control first and then find the repeater inside it).

Also, ensure you are using rep_hello ID not innerRepeater.

BTW< you can do this in the markup too...

<asp:repeater runat="server" id="innerRepeater"
    DataSource='<%# Eval("PropertyInParentObject") %>'  >
    ....
    ....
</asp:repeater>

You can use Container.DataItem instead of Eval too (and cast it to the type of the object in parent repeater item).

这篇关于如何绑定内中继?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 10:15