Add Countries in Your DropDownList Using WebService

Here is the code to add countries in your DropDownList using WebService.

Here I am using a webservice from and a link to the webservice used is

In the .aspx page put a
DropDownList as in the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<html xmlns="">

<head id="Head1" runat="server">




    <form id="form2" runat="server">


    <asp:DropDownList ID="drpCNT" runat="server"></asp:DropDownList>





Now to add the reference of your webservice, do following

  1. Open Solution Explorer, select your website and right-click and select "Add Web Reference"
  2. Now the following window will be opened, enter "" in the URL area that is circled in the image and press Enter.


  3. Now change Web reference name (optional) and click the "Add Reference" Button (circled in the image).


    After that it will create the following structure in Solution Explorer.

  4. Now put the following code in the .aspx.cs file (explained in code):

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Xml;

    using System.Text;


    public partial class _Default : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)


            if (IsPostBack == false)


                //get reference of your webservice

       ct = new;


                // str is an XML String which will hold all the countries in xml format

                string str = ct.GetCountries();


                // add first item in dropdownlist



                //Create an XML Document and load your XML

                XmlDocument doc = new XmlDocument();



                //Get your nodes, here our node in Table because webservice will give us following format


                XmlNodeList nodes = doc.DocumentElement.SelectNodes("//Table");


                //Iterates for xml nodes and add them in dropdownlist

                foreach (XmlNode node in nodes)








  5. Finally you will get all the countries in your DropDownList.