2014-02-07 116 views
0

有沒有辦法在asp.net中做onChange事件<selec>選擇屬性onChange事件

我曾嘗試

protected void Status_Change(object sender, EventArgs e) 

編輯: 問題:背後

代碼:

protected void Status_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    this.Label1.Text = "ok"; 
} 

HTML:

<form id="form2" runat="server"> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    <br /> 
    <br /> 
    <select id="Status" name="Status" class="regis" style="width:170px" onselectedindexchanged="Status_SelectedIndexChanged"> 
     <option value="0">1</option> 
     <option value="1">2</option> 
    </select> 
</form> 

爲什麼犯規工作? TNX的幫助:d

+0

其選定的索引更改事件 – Rex

回答

0
<asp:DropDownList ID="ddlselect" runat="server" AutoPostBack="True" 
     onselectedindexchanged="ddlselect_Changed"> 
    </asp:DropDownList> 

代碼

protected void ddlselect_Changed(object sender, EventArgs e) 
{ 

} 
+0

我不爲什麼它沒有工作,我添加了我的代碼 – Omer

1

後請添加runat="server"類似以下內容:

<select id="Status" name="Status" class="regis" style="width:170px" onselectedindexchanged="Status_SelectedIndexChanged" runat="server"> 
0

通過更換

<select id="Status" name="Status" class="regis" style="width:170px" onselectedindexchanged="Status_SelectedIndexChanged"> 
<option value="0">1</option> 
<option value="1">2</option> 
</select> 
<asp:DropDownList ID="Status" runat="server" Width="200px" onselectedindexchanged="Status_SelectedIndexChanged"> 
     <asp:ListItem Value="0">1</asp:ListItem> 
     <asp:ListItem Value="1">2</asp:ListItem> 
</asp:DropDownList>