3

I have a dropdownlist that is populated by a webservice using the ajax cascading dropdown. I have not been able to set the selected value using javascript. It appears that the values do not exist when the javascript runs. I placed the javascript at the bottom of the aspx page. Any ideas. Here is all of the code and the javascript I have tried.

<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>

1 Answer 1

1

No, you cannot set the value from code-behind; you would have to use JavaScript to set the selected value if binding from a web service. The web service binds everything after the server-side process runs and can only be affected by javascript.

HTH.

Sign up to request clarification or add additional context in comments.

1 Comment

Any chance you can provide a code sample. Everything I have tried does not work. I added a javascript block to the bottom of the aspx page. It does not appear that the field options do not exist when the javascript runs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.