简体   繁体   中英

Calling a function in Aspx.cs with change in dropdownbox

I have a page where in a change in the value from the drop down box will pass the corresponding text in the drop down box to get the values from the database.

<asp:DropDownList ID="dropid" runat="server" OnChange="Getvaluesfromaspx"></asp:DropDownList>

I want the function named "Getvaluesfromaspx" in the aspx.cs to be called from the aspx file. Please help.

Use "OnSelectedIndexChanged" event instead of "OnChange" event.

Also set AutoPostBack property value to true.

<asp:DropDownList ID="dropid" AutoPostBack="true" runat="server" OnSelectedIndexChanged="Getvaluesfromaspx"></asp:DropDownList>

And in code behind

protected void Getvaluesfromaspx(object sender, EventArgs e)  
{  
    //Do whatever want to do here. 
} 

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