3

我有一个用整数填充的下拉列表。When "1" is selected, a text box is supposed to appear. 我在另一个项目中做过类似的事情,但在这里行不通。

任何帮助表示赞赏。

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;
    }
}

默认.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>
4

1 回答 1

7

您想将autoPostBack="true"添加到下拉列表。

 <asp:DropDownList ID="ddlHowMany" runat="server"  
                    onselectedindexchanged="ddlHowMany_SelectedIndexChanged" 
                    style="margin-left: 8px" Width="50px" AutoPostBack="true">
于 2013-03-11T20:16:09.397 回答