![](/img/trans.png)
[英]ASP.Net RadioButtonList SelectedIndexChanged event not firing
[英]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>
</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.