为Web服务填充的下拉列表设置选定的值

时间:2011-02-04 18:38:08

标签: javascript asp.net

  

可能重复:
  Set selectedvalue for a dropdownlist populated by web service

我有一个下拉列表,该列表由使用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 个答案:

没有答案