o422-4349207 info@abiletechnologies.com

how to bind xml data to dropdownlist/gridview in asp.net


Here I will explain how to read data from xml file and bind xml data to dropdownlist or gridview in asp.net.
In previous articles I explained articles relating to XMLsome of those are read xml node values and bind data to gridview and how to insert and read data from xml in asp.net. In situation I got requirement like read data from xml file and display it on webpage. My XML File Name as “Sample.xml” and that would contains data like this

<?xml version=”1.0″ encoding=”utf-8″ ?>

                   <Job>Team Leader</Job>
                   <Job>Software Developer</Job>
                   <Job>Business Analyst</Job>
Now I need to get values from this xml file and bind that data to gridview and dropdownlist for that first create xml file in your application and give name as “SampleXML.xml” and write following code in your aspx page like this

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>
<title>Read Data from XML and Bind Data to gridview/dropdownlist in asp.net</title>
<form id=”form1″ runat=”server”>
<td><b>Dropdown List</b></td>
<td><asp:DropDownList ID=”ddlDetails” runat=”server”/></td>
<td><b>Gridview Details</b></td>
<asp:GridView ID=”gvDetails” runat=”server”>
<HeaderStyle BackColor=”#df5015″ Font-Bold=”true” ForeColor=”White” />
After that add following namespaces in codebehind
About the author