Click here to Skip to main content
15,885,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
ASP.NET
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="extra.aspx.vb" Inherits="dropdownBind.extra" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Bind Dropdownlist with JQuery in asp.net</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
           url: "extra.aspx/BindDatatoDropdown",
             data: "{}",
            dataType: "json",
            success: function (data) {
                $.each(data.d, function (key, value) {
                    $("#ddlCountryd").append($("<option></option>").val(value.CountryId).html(value.CountryName));
                });
            },
            error: function (result) {
                alert("Error");
            }
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DropDownList ID="ddlCountryd" runat="server" />
    </div>
    </form>
</body>
</html>
______________________________________________
C#
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

<system.web.script.services.scriptservice>
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()
                details.Add(country)
            Next

            Return details.ToArray()
    End Function

    Public Class CountryDetails
        Public Property CountryId() As String
            Get
                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
            Get
                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.
Posted
v2
Comments
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