我有一个下拉列表,该列表由使用ajax级联下拉列表的webservice填充。我无法使用javascript设置所选值。当javascript运行时,似乎不存在这些值。我将javascript放在aspx页面的底部。有任何想法吗。这是我尝试过的所有代码和javascript。
<asp:DropDownList ID="ddlBusinessArea" runat="server"></asp:DropDownList>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlBusinessArea"
Category="BusinessArea" ServiceMethod="GetBusinessArea" ServicePath="DropDownFilter.asmx"
LoadingText="Please Wait.....">
</cc1:CascadingDropDown>
<WebMethod()> _
Public Function GetBusinessArea() As CascadingDropDownNameValue()
Dim values As New List(Of CascadingDropDownNameValue)()
Dim objData As clsDataAccess = New clsDataAccess()
Dim ds As DataSet = New DataSet
Dim SQL = "select Description from tblvalidation where MyType = 'Business Area' order by description"
ds = objData.SQLExecuteDataset(SQL)
For Each dr As DataRow In ds.Tables(0).Rows
values.Add(New CascadingDropDownNameValue(dr("Description"), dr("Description")))
Next
Return values.ToArray
End Function
<script type="text/javascript">
var e = document.getElementById("<%=ddlBusinessArea.ClientID%>");
e.options[e.selectedIndex].value = "12345"
document.getElementById("<%=ddlBusinessArea.ClientID%>").value = "12345"
document.getElementById("ctl00_ContentPlaceHolder2_ddlBusinessArea").value = "12345"
</script>
答案 0 :(得分:1)
不,你不能从代码隐藏中设置值;如果从Web服务绑定,则必须使用JavaScript来设置所选值。 Web服务在服务器端进程运行后绑定所有内容,并且只能受到javascript的影响。
HTH。