문제

I would like to know how you get the current control in an asp repeater. 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).

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:

<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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top