Dropdown binding using Jquery in VB.NET

Unknown | 8:33 PM |

In ASPX page:


<script type="text/javascript">
            var pageUrl = '<%=ResolveUrl("~/BOLSup.aspx")%>'
            function PopulateRecLoc() {
                $("#<%=comboFacility.ClientID%>").attr("disabled", "disabled");

                if ($('#<%=comboRecievingLocation.ClientID%>').val() == "0") {
                    $('#<%=comboFacility.ClientID %>').empty().append('<option selected="selected" value="0">Select</option>');

                }
                else {
                    $('#<%=comboFacility.ClientID %>').empty().append('<option selected="selected" value="0">Loading...</option>');
                    var reclocid = $('#<%=comboRecievingLocation.ClientID%>').val()
                    $("#<%= hdnreclocid.ClientID %>").val(reclocid);
                    var hval = document.getElementById('<%=hdnreclocid.ClientID %>').value;

                    $.ajax({
                        type: "POST",
                        url: pageUrl + '/PopulateFacility',
                        data: '{RecLocId: ' + $('#<%=comboRecievingLocation.ClientID%>').val() + '}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function OnCountriesPopulated(response) {

                            PopulateControl(response.d, $("#<%=comboFacility.ClientID %>"));
                        },
                        failure: function (response) {
                            alert(response.d);
                        }
                    });
                }
         

            function PopulateControl(list, control) {
                if (list.length > 0) {
                    control.removeAttr("disabled");
                    control.empty().append('<option selected="selected" value="0">Select</option>');
                    $.each(list, function () {
                        control.append($("<option></option>").val(this['Value']).html(this['Text']));
                    });
                }
                else {
                    control.empty().append('<option selected="selected" value="0">Not available<option>');
                }
            }
        </script>




    <asp:DropDownList runat="server" ID="comboRecievingLocation" Width="205Px" onchange="PopulateRecLoc()"
                                                                    CausesValidation="false">
                                                                </asp:DropDownList>






Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data
Imports System.Collections
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Specialized
Imports AjaxControlToolkit
Imports System.Web.SessionState

Public Class BOLSup
    Inherits System.Web.UI.Page
    Implements IRequiresSessionState
 

    <System.Web.Services.WebMethod()> _
    Public Shared Function PopulateFacility(ByVal RecLocId As Integer) As ArrayList
        Dim list As ArrayList = New ArrayList
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("SurgereConnection").ConnectionString
        Dim strQuery As String = "select facility_id,facility_name from Facility where facility_type<>'Consolidation Center' and location_id=@location_id"
        Dim con As SqlConnection = New SqlConnection(strConnString)
        Dim cmd As SqlCommand = New SqlCommand
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@location_id", RecLocId)
        cmd.CommandText = strQuery
        cmd.Connection = con
        con.Open()
        Dim sdr As SqlDataReader = cmd.ExecuteReader
        While sdr.Read
            list.Add(New ListItem(sdr("facility_name").ToString, sdr("facility_id").ToString))
        End While
        con.Close()
        Return list
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....