Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

return dropwdown list values with JSON

$
0
0

I have dropwdownlists that sit in a modalpopup and I amtrying to fill one with value picked from another.  I have a lot of it figured out but it seems to error out on me every time and i think it has to do with way i am filling it but not sure.  All's i ever get back is the alert error.

 

$(document).ready(function() {
                $('#' + '<%= ddlRecTeam.ClientID%>').change(function(e) {
                    var team_id = $('#' + '<%= ddlRecTeam.ClientID%>').val();
                    var station = document.getElementById("divStation").style.display = "inline"
                    if (team_id == 0) { //if there is no country select
                           $('#' + '<%= ddlStation.ClientID%>').children().remove();
                           $('#' + '<%= ddlStation.ClientID%>').append('<option value="0">You must select country</option>');
                       }
                       else {
                           $.ajax({ type: "POST",
                               url: "Recruiting.asmx/getStations", //web service and function name
                               data: "{id:" + team_id + "}", // passing parameter
                               contentType: "application/json; charset=utf-8",
                               dataType: "json",
                               success: function(response) {
                                   var result = response.d;
                                   //remove previews cities
                                   $('#' + '<%= ddlStation.ClientID%>').children().remove();
                                   //looping to add cities as option
                                   $.each(result, function(index, res) {
                                       $('<option></option>', {
                                           value: res.cityID,
                                           text: res.cityName
                                       }).appendTo('#' + '<%= ddlStation.ClientID%>');
                                       $("#loading").hide();

                                   });
                               },
                               error: function(msg) {
                                   alert("Error");
                               }
                           });
                       }
                   });
             });


class for the service and the amsx service code.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports RecruitCommon
Imports System.Data

Public Class Stations
    Public station As String
    Public stationId As Integer
End Class

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _<WebService(Namespace:="http://tempuri.org/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Recruiting
    Inherits System.Web.Services.WebService<WebMethod()> _
    Public Function getStations(ByVal sLookUP As Integer) As Stations()
        Dim station As New List(Of Stations)

        sql = "select intstationId, strstationCode + ' - ' + strStationname from Station where intTeamID = " & sLookUP
        HttpContext.Current.Response.Write(sql)
        HttpContext.Current.Response.End()
        myDataTable = New DataTable
        myDataTable = getData(sql)

        If myDataTable.Rows.Count > 0 Then
            For Each dRow As DataRow In myDataTable.Rows
                Dim stations As New Stations()
                stations.station = dRow(0)
                stations.stationId = dRow(1)
                station.Add(stations)
            Next
        End If

        Return station.ToArray
    End Function
End Class


Viewing all articles
Browse latest Browse all 23244

Trending Articles