programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Friday, April 15, 2016

Bind xml data to dropdownlist or gridview in

 In how to bind xml data to drop down list or gridview in

In previous post I explained post relating to XML some of those are read xml file and bind data to grid view and how to insert and read data from xml in In situation I got requirement like read data from xml file and display it on webpage. My XML File Name as “SampleDemofor.xml” and that would contains data like this

<?xml version="1.0" encoding="utf-8" ?>
                   <Job>Software Team Leader </Job>
                   <Job>Software Developer in</Job>

Now We 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 “SampleDemoforXML.xml” and write following code in your aspx page like this

<html xmlns="">
<head runat="server">
<title>Read Data from XML and Bind Data to gridview/dropdownlist in</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" />

C# Code bind from XML Data:

using System;
using System.Data;
using System.Xml;

protected void Page_Load(object sender, EventArgs e)

protected void BindDataToGridviewDropdownlist()
XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("SampleDemofor.xml"));
DataSet ds = new DataSet();
if (ds.Tables.Count != 0)
//Bind Data to gridview
gvDetails.DataSource = ds;
//Bind Data to dropdownlist
ddlDetails.DataSource = ds;
ddlDetails.DataTextField = "UserName";
ddlDetails.DataValueField = "UserName";


Other Related Post :

No comments:

Post a Comment