Add Countries in your DropDpwnList Using WebService

Hello friends,

Here is the code to add Countries in your dropdownlist using WebService…

Here i am using a webservice from and link of used webservice is .

In .aspx page put a dropdown list

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

<!DOCTYPE html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN’ ‘’&gt;

<html xmlns=””&gt;
<head runat=”server”>
<form id=”form1″ runat=”server”>
<asp:DropDownList ID=”drpCNT” runat=”server”></asp:DropDownList>

Now to add the reference of your webservice, do following steps…

1. open Solution explorer , select your website and right click and select the option Add Web Reference

2. Now following window will be opened , put in URL area that is circled in image.


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


4. Now put the following code in .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…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s