Click here to Skip to main content
13,404,807 members (36,209 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone,

This is my webservice method.
    public List<cls_Countries> GetCountries()
        cls_GetLocations locations = new cls_GetLocations();
        return locations.GetCountries();

This is my method in class
public cls_GetLocations()
        public List<cls_Countries> GetCountries()
            List<cls_Countries> list=new List<cls_Countries>();
                DataTable dt= SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.StoredProcedure, "Proc_GetCountries").Tables[0];
                foreach (DataRow dr in dt.Rows)
                    cls_Countries country = new cls_Countries();
                    country.CountryID = dr["CountryId"].ToString();
                    country.CountryName = dr["Country"].ToString();
            catch (Exception ex)
                throw (ex);

            return list;

I want to bind to drop down I tried below code but it wont work so please solve and provide me correct solution

<script type="text/javascript" >

    $(function () {
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'WebServices/AutoComplete.asmx/GetCountries',
            data: "{}",
            datatype: "json",
                function (data, event) {
                    $.map(data.d, function (item) {
                        //$("#<%= drpCountry.ClientID %>").index = item.countryid;
                        //$("#<%= drpCountry.ClientID %>").val = item.countryname;


Posted 15-Jan-13 1:33am
Updated 15-Jan-13 1:36am
Member 9581488 15-Jan-13 16:00pm
what is the error?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

List<Customer> _customer = new CustomerBLL().GetAllCustomers();
  if (_customer != null)
    ddlCustomer.DataSource = _customer;
    ddlCustomer.DataValueField = "CustomerId";
    ddlCustomer.DataTextField = "CustomerName";
    ddlCustomer.Items.Insert(0, new ListItem("Select Customer", "0"));

Try to use this code.
Here GetAllCustomers(); is the method which returns List of customer and the method is in CustomerBLL() class. The method returns CustomerId, CustomerName & so on as a List. In the drop-down list i'm binding CustomerId as "DataValueField" & CustomerName as "DataTextField". And the last of all i'm adding "Select Customer" at the top of the drop-down list, thought you may need it so i add it too.

Hope it would help you.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180221.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100