简体   繁体   English

在asp.net中继器中获取当前控件

[英]Getting the current control in an asp.net repeater

I would like to know how you get the current control in an asp repeater. 我想知道如何在ASP中继器中获得当前控件。 I would like the repeater to display a text-box control when the ID is 1 and radio button when 2. But when hiding this control, I don't want all previous and future controls that should be visible to be hidden (this is the part I am struggling with). 我希望中继器在ID为1时显示文本框控件,在ID为2时显示单选按钮。但是在隐藏此控件时,我不希望所有应该可见的以前和将来的控件都被隐藏(这是我正在努力的部分)。

Please see the following: 请参阅以下内容:

<asp:Repeater ID="rptQuestionnaireQuestions" runat="server" OnItemDataBound="rptQuestionnaireQuestions_ItemDataBound">
        <ItemTemplate>
            <p><%# Eval("QuestionnaireQuestionTitle") %></p>
            <asp:Panel ID="pnlTypeText" runat="server">
                <asp:TextBox ID="txtResponse" runat="server" />
            </asp:Panel>
            <asp:Panel ID="pnlTypeRadio" runat="server">
                <p><%# Eval("QuestionnaireAnswerTitle") %></p>
                <asp:RadioButton ID="rbResponse" runat="server" />
            </asp:Panel>
            <asp:Panel ID="pnlTypeRadioMultiple" runat="server">
                <asp:GridView ID="gviDisplayMultiple" runat="server"
                    OnRowDataBound="gviDisplayMultiple_RowDataBound"
                    AutoGenerateColumns="false" />
            </asp:Panel>
        </ItemTemplate>
    </asp:Repeater>

Many thanks. 非常感谢。

Here is how you can set Visible property either for the control, or for the wrapping panel: 这是您可以为控件或包装面板设置Visible属性的方法:

<asp:Panel ID="pnlTypeText" runat="server"
           Visible='<%# (int)Eval("ID") == 1 %>'>
    <asp:TextBox ID="txtResponse" runat="server" />
</asp:Panel>
<asp:Panel ID="pnlTypeRadio" runat="server"
           Visible='<%# (int)Eval("ID") == 2 %>'>
    <p><%# Eval("QuestionnaireAnswerTitle") %></p>
    <asp:RadioButton ID="rbResponse" runat="server" />
</asp:Panel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM