如何从下拉列表中选择特定选项时返回文本

时间:2016-03-13 13:40:00

标签: asp.net drop-down-menu autocomplete webforms

我的代码包含下拉列表,从中选择任何选项,然后其他选项必须自动填充

         <td>Annual Income</td>
            <td>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Value="1">100000</asp:ListItem>
                    <asp:ListItem Value="2">50000</asp:ListItem>
                    <asp:ListItem Value="3">25000</asp:ListItem>
                    <asp:ListItem Value="4">10000</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>Basic Pay</td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>HRA</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>Tax</td>
            <td>
                <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            </td>

此代码从下拉列表中选择annual income,然后必须自动选择基本和hra

1 个答案:

答案 0 :(得分:2)

在服务器端添加此功能(假设为C#)

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedValue.Equals("1"))
    {
        TextBox3.Text = "10000";
        TextBox4.Text = "500";
    }
}
相关问题