我有一个填充了整数的下拉列表.选择“1”时,应显示文本框.我在另一个项目中做过类似的事情,但在这里不行. 任何帮助表示赞赏. C#代码: protected void Page_Load(object sender, EventArgs e){ if
任何帮助表示赞赏.
C#代码:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlHowMany.Items.Add(new ListItem("0", "0")); ddlHowMany.Items.Add(new ListItem("1", "1")); ddlHowMany.Items.Add(new ListItem("2", "2")); ddlHowMany.Items.Add(new ListItem("3", "3")); } } protected void ddlHowMany_SelectedIndexChanged(object sender, EventArgs e) { // int howMany = Convert.ToInt32(ddlHowMany.SelectedValue); if (ddlHowMany.SelectedIndex == 1) { txtGraphic1Desc.Visible = true; } }
Default.aspx代码:
<asp:DropDownList ID="ddlHowMany" runat="server" onselectedindexchanged="ddlHowMany_SelectedIndexChanged" style="margin-left: 8px" Width="50px"> </asp:DropDownList> <br /> <br /> <asp:TextBox ID="txtGraphic1Desc" class="descriptions" runat="server" Height="92px" TextMode="MultiLine" Width="328px" Font-Names="Trebuchet MS" Visible="False">Description of graphic #1</asp:TextBox>您想要将 autoPostBack=”true”添加到下拉列表中.
<asp:DropDownList ID="ddlHowMany" runat="server" onselectedindexchanged="ddlHowMany_SelectedIndexChanged" style="margin-left: 8px" Width="50px" AutoPostBack="true">