如何在Child DataLIst控件中访问父级的DataList控件? [英] How to access parent's DataList control inside Child DataLIst control?

查看:124
本文介绍了如何在Child DataLIst控件中访问父级的DataList控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从子datalist控件访问父级datalist的标签文本:ImageButtom点击事件。

I want to access parent datalist's label text from child datalist control: ImageButtom click event.

<div>
        <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <div>
            <asp:DataList ID="DataList2" runat="server">
                <asp:ImageButton runat="server">
                </asp:ImageButton>
            </asp:DataList>
        </div>
        </ItemTemplate>
        </asp:DataList>
    </div>

推荐答案

请参阅: https:// msdn .microsoft.com / zh-CN / library / system.web.ui.control.parent%28v = vs.110%29.aspx [ ^ ]。



在你的情况下,这是采取父母的几个步骤,直到你达到你感兴趣的控制。



或者,您只需找到所需的控件实例 id 并将其转换为预期的控件类型。



-SA
Please see: https://msdn.microsoft.com/en-us/library/system.web.ui.control.parent%28v=vs.110%29.aspx[^].

In your case, this is making several step of taking a parent until you reach the control you are interested it.

Alternatively, you can simply find the control instance you need id and cast it to the expected control type.

—SA


这篇关于如何在Child DataLIst控件中访问父级的DataList控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆