Ajax Cascading DropDown List

HelloBlue

New member
Joined
Oct 21, 2008
Messages
2
Programming Experience
Beginner
Hi, I have 2 dropdownlists and 2 CCD extenders

I have 1 Database table. The first ddl reads from the table and displays the Work Centre which is a string value. The second ddl should display the ID( is also a string value) based on the Work Centre passed to it. My db does not have an unique id column

How do I pass a string value to the second ddl ? My code below:

HTML:
<form id="form1" runat="server">
   
      <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
       
        Type:
        <asp:DropDownList ID="type" runat="server">
        </asp:DropDownList> <br />
        <cc1:cascadingdropdown id="ccdType" runat="server"
        TargetControlID="type" ServicePath="MachineService.asmx" ServiceMethod="GetTypes" Category="WorkCentre"
        PromptText="Select Type"></cc1:cascadingdropdown>
     
    
        Machine ID

        <asp:DropDownList ID="MachineID" runat="server">
        </asp:DropDownList><br />
        <cc1:CascadingDropDown ID="ccdWorkCentre" runat="server" TargetControlID="MachineID"
        ServicePath="MachineService.asmx" ServiceMethod="GetMachineID"
        ParentControlID="type" Category="Machine_ID" PromptText="Select Catergory">
        </cc1:CascadingDropDown>
       
    </form>

My Webservice Code:

VB.NET:
    <WebMethod()>  _
    Public Function GetTypes(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
        Dim conn As SqlConnection = New SqlConnection("server=.; Integrated Security=true; Initial Catalog=Production Play")
        conn.Open
        Dim comm As SqlCommand = New SqlCommand("SELECT DISTINCT Work_Centre FROM dbo.PFTbl_Machines", conn)
        Dim dr As SqlDataReader = comm.ExecuteReader
        Dim one As List = New List
        
        While dr.Read
            one.Add(New CascadingDropDownNameValue(dr("Work_Centre").ToString, ""))
            
        End While
        conn.Close
        Return one.ToArray
    End Function
    
    <WebMethod()>  _
    Public Function GetMachineID(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
        'int RecordID;
        Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(k, nownCategoryValues)
        If (Not kv.ContainsKey("WorkCentre")  _
                    OrElse Not Int32.TryParse(kv("WorkCentre"), RecordID)) Then
            Throw New ArgumentException("Couldn't find WorkCentre.")
        End If
        Dim conn As SqlConnection = New SqlConnection("server=.; Integrated Security=true; Initial Catalog=Production Play")
        conn.Open
        Dim comm As SqlCommand = New SqlCommand("SELECT Machine_ID WHERE Work_Centre = @Work_Centre", conn)
        comm.Parameters.AddWithValue("@Work_Centre", RecordID)
        Dim dr As SqlDataReader = comm.ExecuteReader
        Dim one As List = New List
        
        While dr.Read
            one.Add(New CascadingDropDownNameValue(dr("Machine_ID").ToString, ""))
            
        End While
        conn.Close
        Return one.ToArray
    End Function
 
Last edited by a moderator:
This is a VB.Net forum site, I translated your C# post to VB.Net. I also formatted the post for readability. Take care!
 
Back
Top