select属性的onChange事件

时间:2014-02-07 11:34:08

标签: html asp.net

有没有办法在asp.net中为<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

3 个答案:

答案 0 :(得分:1)

请添加runat="server",如下所示:

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

答案 1 :(得分:0)

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

在代码背后

protected void ddlselect_Changed(object sender, EventArgs e)
{

}

答案 2 :(得分: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>