2014-02-07 114 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>