如何在clientSide和ServerSide中使用selectedIndexChanged下拉列表

时间:2012-09-20 16:51:13

标签: c# javascript asp.net drop-down-menu

如何在clientSide和ServerSide中使用asp.net下拉列表中的selectedIndexChanged?

在客户端,我想调用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是clientside中的函数名称!

感谢您的帮助!

2 个答案:

答案 0 :(得分:27)

在下拉列表的onchange事件中添加客户端函数名称,如下所示:

<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" 
      AutoPostBack="True" OnSelectedIndexChanged="SelectedChange" 
      onchange="changeCursor()">
</asp:DropDownList>

答案 1 :(得分:14)

在HTML(.aspx)

<asp:DropDownList ID="DropDownSubject" runat="server" DataTextField="Word" AutoPostBack="True" 
         OnSelectedIndexChanged="SelectedChange" onchange="YourChangeFun(this);">
</asp:DropDownList>

在javascript中

<script type="text/javascript">
      function YourChangeFun(ddl)
      {
         alert(ddl.selectedIndex);
      }
</script>