How to bind dropdown list with XML file in

  ASP.NET   Thursday, February 18, 2016   4596 | 54 Comments | Not Downloaded Yet!!! | No Demo | Pawan kumar
 Tags: bind dropdown list with XML file in 


Here Pawan Kumar will explain How to bind dropdown list with XML file in


In previous post I have explained Show Asp.Net Gridview Row Details using Bootstrap Tooltip on MouseHover GridView Row Cell, Best 7 Resources for 3 tier architecture Asp.Net, Show Hide Password Using Javascript ASP.NET, How to Create Tab Control Using jQuery In Asp.Net, jQuery Datepicker Calendar With Slide Down Effect In Asp.Net, jQuery Code To Select Multiple Item By Pressing Ctrl Button In Asp.Net, and many more articles.

Now I will explain How to How to bind dropdown list with XML file in

So follow the steps to learn How to bind dropdown list with XML file in

Step 1: Create a website

Step 2: Create a XML file with name Departments.xml and save to root of the website.

<?xml version="1.0" encoding="utf-8" ?>
    <deptName>Human Resource</deptName>
    <deptName>Information Technology</deptName>
    <deptName>System Network</deptName>
    <deptName>Customer Support</deptName>

Step 3 : Add a new webpage and write the below codes:-

<%@ 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>Sample binding xml file into dropdown list</title>
    <form id="form1" runat="server">
            Department :
            <asp:DropDownList ID="DrpDepartment" AutoPostBack="true" runat="server">

Step 4: Add the following codes to code behind file.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)

        catch (Exception ex)

    private void LoadDropdownList()
            DataSet dsDept = new DataSet();
            DrpDepartment.DataSource = dsDept;
            DrpDepartment.DataTextField = "deptName";
            DrpDepartment.DataValueField = "deptId";
            DrpDepartment.Items.Insert(0, new ListItem("-- Select --", "0"));

        catch (Exception ex)
            throw ex;



So, In this tutorial we have learned, How to bind dropdown list with XML file in

Download Source Codes

Post Comments

if you have some suggestion, question, request on How to bind dropdown list with XML file in

Please use the comment box to express your views.