简体   繁体   中英

html select (dropdown) control selected index changed event in asp.net

I am trying to put backend code to my html select control (dropdown) when the value is changed a backend method to be triggered, but I Can't find the event. I tried this way:

<select id="ddlCompany" name="select2" onchange="ddlCompany_SelectedIndexChanged" runat="server" class="dropdown nostyle sel1" style="width:100%;" placeholder="Select Company" />

nothing changes. Can anyone advice how I can fix this? Thx, Laziale

Add this to your code behind:

protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
{
     //code here
}

And this to your markup:

OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" AutoPostBack="True"

尝试使用SelectedIndexChanged属性而不是onchange,如下所示:

<select id="ddlCompany" name="select2" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" runat="server" class="dropdown nostyle sel1" style="width:100%;" placeholder="Select Company" />

If you are using the dropdownlist server control. Go to the designer view, Select the dropdownlist server control and right click and select Properties . Now in the properties window, click on the Events icon and then you can see the SelectedIndexChanged event. Double click on the blank white space on the right side and Visual studio will generate the relevant code for you.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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