索引更改时不会触发 SelectedIndexChanged 事件
SelectedIndexChanged event does not get fired on Index change
我在 asp.net
中有以下 dropdownList
控件
<asp:dropdownlist id="ddlMerchantCity" runat="server"></asp:dropdownlist>
我想在其 SelectedIndexChanged
事件上调用一个方法,但它不会进入 SelectedIndexChanged 事件的主体。我的代码有什么问题?
Protected Sub ddlMerchantCity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlMerchantCity.SelectedIndexChanged
Response.Write("<script>alert('from selectindex')</script>")
LoadMerchant()
End Sub
编辑:
即使在 asp.net 下拉列表中添加 OnSelectedIndexChanged
也不起作用
<asp:dropdownlist id="ddlMerchantCity" runat="server" OnSelectedIndexChanged="ddlMerchantCity_SelectedIndexChanged"></asp:dropdownlist>
当这个事件发生时,编译器不知道你有一个方法来做某事。您可以通过在 aspx 标记中定义它来调用此方法:
<asp:dropdownlist id="ddlMerchantCity" runat="server" OnSelectedIndexChanged="ddlMerchantCity_SelectedIndexChanged" AutoPostBack="true"></asp:dropdownlist>
或者你可以在后面的代码中设置:
AddHandler ddlMerchantCity.SelectedIndexChanged, AddressOf Me.ddlMerchantcity_SelectedIndexChanged
不过我宁愿通过标记来完成。更快更容易。
/编辑:
如果添加 OnSelectedIndexChanged
没有帮助,您可能必须设置 AutoPostback="true"
要在 AutoPostBack 描述中引用 MSDN:
Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection.
我在 asp.net
中有以下dropdownList
控件
<asp:dropdownlist id="ddlMerchantCity" runat="server"></asp:dropdownlist>
我想在其 SelectedIndexChanged
事件上调用一个方法,但它不会进入 SelectedIndexChanged 事件的主体。我的代码有什么问题?
Protected Sub ddlMerchantCity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlMerchantCity.SelectedIndexChanged
Response.Write("<script>alert('from selectindex')</script>")
LoadMerchant()
End Sub
编辑:
即使在 asp.net 下拉列表中添加 OnSelectedIndexChanged
也不起作用
<asp:dropdownlist id="ddlMerchantCity" runat="server" OnSelectedIndexChanged="ddlMerchantCity_SelectedIndexChanged"></asp:dropdownlist>
当这个事件发生时,编译器不知道你有一个方法来做某事。您可以通过在 aspx 标记中定义它来调用此方法:
<asp:dropdownlist id="ddlMerchantCity" runat="server" OnSelectedIndexChanged="ddlMerchantCity_SelectedIndexChanged" AutoPostBack="true"></asp:dropdownlist>
或者你可以在后面的代码中设置:
AddHandler ddlMerchantCity.SelectedIndexChanged, AddressOf Me.ddlMerchantcity_SelectedIndexChanged
不过我宁愿通过标记来完成。更快更容易。
/编辑:
如果添加 OnSelectedIndexChanged
没有帮助,您可能必须设置 AutoPostback="true"
要在 AutoPostBack 描述中引用 MSDN:
Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection.