Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="extra.aspx.vb" Inherits="dropdownBind.extra" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <title>Bind Dropdownlist with JQuery in</title>
    <script type="text/javascript" src=""></script>
<script type="text/javascript">
    $(document).ready(function () {
            type: "POST",
            contentType: "application/json; charset=utf-8",
           url: "extra.aspx/BindDatatoDropdown",
             data: "{}",
            dataType: "json",
            success: function (data) {
                $.each(data.d, function (key, value) {
            error: function (result) {
    <form id="form1" runat="server">
      <asp:DropDownList ID="ddlCountryd" runat="server" />
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services

Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Text.RegularExpressions
Imports System.Collections
Imports System.Diagnostics
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Net
Imports System.Threading
Imports System.Web.Services.Protocols
Imports System.Globalization
Imports System.Web.Script.Serialization
Imports System.Web.Configuration

Public Class extra
    Inherits System.Web.UI.Page

    Public Shared webService As New webSer.Service1

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

    End Sub

 <webmethod()> _
    Public Shared Function BindDatatoDropdown() As CountryDetails()
        Dim dt As New DataTable()
        Dim details As New List(Of CountryDetails)()
        Dim branchCode As String = "002"
        Dim strCon As String = "002_001;"
        Dim dst As New DataSet()
        dst = webService.getCustomerDs(branchCode, strCon)
        dt = dst.Tables(0)
            For Each dtrow As DataRow In dt.Rows
                Dim country As New CountryDetails()
                country.CountryId = dtrow("custcode").ToString()
                     country.CountryName = dtrow("customer").ToString()

            Return details.ToArray()
    End Function

    Public Class CountryDetails
        Public Property CountryId() As String
                Return m_CountryId
            End Get
            Set(ByVal value As String)
                m_CountryId = value
            End Set
        End Property
        Private m_CountryId As String
        Public Property CountryName() As String
                Return m_CountryName
            End Get
            Set(ByVal value As String)
                m_CountryName = value
            End Set
        End Property
        Private m_CountryName As String
    End Class

End Class


Here, webservice calling from hosted.

If we are giving sql command from local (i.e "select * from ___ "), it is working.

If it is from webservice, it is not working. Please help.
You have to debug and find out the issue. We cannot guess from the code. Also refer the browser console if you see any errors there.
Member 11922091 20-Aug-15 8:02am    
but, while debugging the data is getting in the dataset. But it shows the else condition. That means it going to the error message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900