简体   繁体   English

在下拉框中更改时调用Aspx.cs中的函数

[英]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. 我希望从aspx文件中调用aspx.cs中名为“ Getvaluesfromaspx”的函数。 Please help. 请帮忙。

Use "OnSelectedIndexChanged" event instead of "OnChange" event. 使用“ OnSelectedIndexChanged”事件而不是“ OnChange”事件。

Also set AutoPostBack property value to true. 还将AutoPostBack属性值设置为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. 
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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