0

簡単に言うと、ドロップダウンから「その他」のドロップダウンオプションが選択されたときにのみ表示され、別の選択が行われると消える ID="textComments" のテキストボックスが必要です。JS でこれを行うこともできますが、C# で行う必要があります。

<asp:DropDownList runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
    <asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
    <asp:ListItem Value="Website" Text="Website"></asp:ListItem>
    <asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
    <asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>

<asp:label runat="server" ID="lblComments" AssociatedControlID="textComments" CssClass="textLabel">Comments:</asp:label>
<asp:TextBox runat="server" MaxLength="200" TextMode="MultiLine" Columns="40" Rows="4" ID="textComments" Wrap="true" CssClass="textComments"></asp:TextBox>

そして、助けていただければ幸いです。

4

2 に答える 2

2
  • 最初にDropDownListするAutoPostBack=true
  • SelectedIndexChanged-イベントを処理する
  • そこで両方のコントロールの可視性を切り替えます

aspx:

<asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="dropEnquiryType_Changed" runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
    <asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
    <asp:ListItem Value="Website" Text="Website"></asp:ListItem>
    <asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
    <asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>

コードビハインド:

protected void dropEnquiryType_Changed(Object sender, EventArgs e)
{
    lblComments.Visible = dropEnquiryType.SelectedValue == "Other";
    textComments.Visible = lblComments.Visible;
}
于 2013-07-03T15:23:04.077 に答える