Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Bind DropDownList using XML File

Viewed:  1762 
Posted On:  25/04/2013 10:14:34 
How to bind a drop down list control using xml file in ASP.NET. 

In this article I am going to show how to bind a drop down list control using XML file.

below is my XML file...


Image 1.

My program output will be:


Image 2.

My aspx code is :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>>Bind DropDownList Using XML File. | Dot Net CodeSG</title>
    <form id="form1" runat="server">
        <table cellpadding="20" cellspacing="20" width="40%" align="center" border="2">

<td align="center">
                    <asp:DropDownList ID="ddlCountry" runat="server" Width="170px">
My aspx.cs code is:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            DataSet dataSet = new DataSet();
            DataView dataView = dataSet.Tables[0].DefaultView;
            dataView.Sort = "Id";
            ddlCountry.DataTextField = "Name";
            ddlCountry.DataValueField = "Name";
            ddlCountry.DataSource = dataView;

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us