C# 如何在客户端和服务器端使用 selectedIndexChanged 下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12517227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How use selectedIndexChanged dropdownlist in clientSide and ServerSide
提问by user1671697
How use selectedIndexChanged from asp.net dropdownlist in clientSide and ServerSide?
如何在 clientSide 和 ServerSide 中使用来自 asp.net 下拉列表的 selectedIndexChanged?
In clientside i want call javascript funcition!
在客户端,我想调用 javascript 函数!
<script type="text/javascript">
function changeCursor() {
document.body.style.cursor="progress";
}
</script>
<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" OnSelectedIndexChanged="SelectedChange">
</asp:DropDownList>
SelectedChange is a name of function in clientside!
SelectedChange 是客户端的函数名!
Thanks for help!
感谢帮助!
采纳答案by Kundan Singh Chouhan
Add your client side function name in onchange events of dropdown like below :
在下拉列表的 onchange 事件中添加您的客户端函数名称,如下所示:
<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word"
AutoPostBack="True" OnSelectedIndexChanged="SelectedChange"
onchange="changeCursor()">
</asp:DropDownList>
回答by Adil
In HTML (.aspx)
在 HTML (.aspx) 中
<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True"
OnSelectedIndexChanged="SelectedChange" onchange="YourChangeFun(this);">
</asp:DropDownList>
In javascript
在 JavaScript 中
<script type="text/javascript">
function YourChangeFun(ddl)
{
alert(ddl.selectedIndex);
}
</script>
回答by Rajnikant
First change autopostback="false" and give onchange="js function()" and remove selected index change event.
首先更改 autopostback="false" 并给出 onchange="js function()" 并删除选定的索引更改事件。

