繁体   English   中英

在 asp.net C# 中第一次执行该事件后,如何让 RadioButtonList_SelectedIndexChanged 事件处理程序执行?

[英]How do I get the RadioButtonList_SelectedIndexChanged event handler to execute after the first execution of that event in asp.net C#?

我有一个带有两个 RadioButtons 的 RadioButtonList,当我单击一个单选按钮时,它会为该选项启用一个 DropDownList。

这是我的 HTML 代码。

<table>
    <tr>
        <td class="auto-style3">
        </td>
        <td style="font-size:medium" class="auto-style3">
           <asp:RadioButtonList ID="Database_Type" runat="server" Height="99px" OnSelectedIndexChanged="Database_Type_SelectedIndexChanged" AutoPostBack="True">
                                <asp:ListItem Text="Standard" Value="1"></asp:ListItem>
                                <asp:ListItem Text="Custom" Value="2"></asp:ListItem>
           </asp:RadioButtonList>
        </td>
        <td>
           &nbsp;&nbsp;</td>
        <td style="font-size:medium" class="auto-style3">
            <asp:DropDownList ID="StandardAircraftList" runat="server"></asp:DropDownList>
            <br />
            <br />
            <asp:DropDownList ID="CustomAircraftList" runat="server"></asp:DropDownList>
        </td>
    </tr>
</table>

这是我的 C# 代码。

protected void Database_Type_SelectedIndexChanged(object sender, EventArgs e)
{
    if (Database_Type.SelectedItem.Value == "1")
    {
        StandardAircraftList.Enabled = true;
        CustomAircraftList.Enabled = false;
        StandardAircraftList.BackColor = System.Drawing.Color.White;
        CustomAircraftList.BackColor = System.Drawing.Color.Gray;
    }
    if (Database_Type.SelectedItem.Value == "2")
    {
        CustomAircraftList.Enabled = true;
        StandardAircraftList.Enabled = false;
        CustomAircraftList.BackColor = System.Drawing.Color.White;
        StandardAircraftList.BackColor = System.Drawing.Color.Gray;
    }
}

请澄清您的预期行为是什么以及现在的行为如何。 该事件已正确连接,并在选择其中一个选项时执行。

如果“第一次执行该事件”实际上是指通常第一次执行后面的代码并且您缺少“默认”行为,则需要为单选按钮实现“默认状态”以及下拉列表,例如

<asp:ListItem Text="Standard" Value="1" Selected="True"></asp:ListItem>

并相应地

StandardAircraftList.Enabled = true;
CustomAircraftList.Enabled = false;
StandardAircraftList.BackColor = System.Drawing.Color.White;
CustomAircraftList.BackColor = System.Drawing.Color.Gray;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM