当我更改下拉列表的选择时,更改事件不会触发。我在方法中放置了一个断点,程序没有停止。
这是我的标记:
<form id="form1" runat="server">
<div style='text-align:center;'>
<a style='text-decoration:none;font-size:16px;color:blue;background-color:white;width:200px;padding:4px;' href='LocationDetails.aspx?Location_ID=0' target='detailPanel'> Add Location
</a></div>
 
<div style='text-align:left;'>
<asp:Label ID="FacilityTypeLbl" runat="server">Facility Type:</asp:Label>
<asp:DropDownList ID="FacilityTypeDDL" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="FacilityTypeDDL_SelectedIndexChanged">
</asp:DropDownList>
</div>
<hr/>
<%ListLocations()%>
</form>这是我的Page_Load方法来填充列表,它工作得很好。
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
GetServiceTypes()
FacilityTypeDDL.DataSource = dtServiceTypes
FacilityTypeDDL.DataTextField = dtServiceTypes.Columns("Title").ToString()
FacilityTypeDDL.DataValueField = dtServiceTypes.Columns("ID").ToString()
FacilityTypeDDL.DataBind()
End If
End Sub这是我的改变事件:
Protected Sub FacilityTypeDDL_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles FacilityTypeDDL.SelectedIndexChanged
strFacilityValue = FacilityTypeDDL.SelectedValue
ListLocations()
End Sub我在第一行代码中放置了一个断点,在更改下拉选择后,它不会在此事件中停止。
我做错了什么?
更新--这是我的全部标记。这有什么问题吗?
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Locations.aspx.vb" Inherits="Editor_Locations" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="LocationHead" runat="server">
<title>Locations</title>
<meta http-equiv="Content-Language" content="en-us"/>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
</head>
<body>
<form id="form1" runat="server">
<div style='text-align:left;'>
<asp:Label ID="FacilityTypeLbl" runat="server">Facility Type:</asp:Label>
<asp:DropDownList ID="FacilityTypeDDL" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="FacilityTypeDDL_SelectedIndexChanged">
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>test2</asp:ListItem>
<asp:ListItem>Test34</asp:ListItem>
</asp:DropDownList>
</div>
<hr/>
</form>
</body>
</html>此应用程序是一个网站,而不是一个web应用程序。(我不知道有什么不同,但现在我知道了。)为了找出SelectedIndexChange事件不会触发的方式,我添加了一个按钮和一个单击事件。当我更改下拉列表中的选择时,没有事件触发。当我单击该按钮时,单击事件触发,然后选择索引更改事件触发。
我不认为事件SelectedIndexChanged会起作用。
当下拉列表发生变化时,还有其他方式连接回发吗?当列表发生变化时,我可以使用javascript函数调用中的__doPostback吗?
如有任何建议,将不胜感激!
发布于 2015-05-04 15:15:42
我无法让asp:DropdownList触发SelectedIndexChanged事件。所以我就是这样完成任务的。
如上面所示,动态添加下拉列表,并添加调用javascript的更改事件:
onchange='UpdateLocationList()'这个函数必须放在一个.js文件中。这个网站已经有了一个.js文件。它还有一些AJAX调用,我用它们来完成任务。在UpdateLocationList()中,我获得了在下拉列表中设置为值属性的服务类型的ID。然后,我使用一个已经是.js文件一部分的函数到LocationDetails页面,使用Service只显示该服务类型的功能。这是一项功能:
function updateLocationList() {
var ddlFacilityType = document.getElementById("FacilityTypeDDL");
var facilityValue = ddlFacilityType.options[ddlFacilityType.selectedIndex].value;
processAjax("/editor/Locations.aspx?Location_ID=" + facilityValue, "navPanel");
}就像一种魅力。
谢谢你的帮助。
https://stackoverflow.com/questions/29976365
复制相似问题