简而言之,我需要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>
非常感谢帮助。
答案 0 :(得分: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;
}
答案 1 :(得分:1)
如果您绝对必须在C#中执行此操作,那么只需在PreRender中进行简单检查即可:
textComments.Visible = (dropEnquiryType.SelectedValue == "Other");
这也需要你在dropEnquiryType上设置AutoPostback,但它使用... JavaScript!