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

Friday, April 15, 2016

Asp.net Gridview displaying XML file data

 Asp.net Gridview displaying XML file data:



In previous post I explained post relating to XML some of those are read xml file and bind data to Asp.net grid view, xml data to dropdownlist or gridview in asp.net 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 “SampleDemofor.xml” and that would contains data like this

Here is the xml file for binding data
    <Employees>
      <Employee>
        <Name>Adams John</Name>
        <Age>35</Age>
        <Gender>M</Gender>
        <Salary>65000</Salary>
      </Employee>
      <Employee>
        <Name>Mary Jane</Name>
        <Age>35</Age>
        <Gender>F</Gender>
        <Salary>75000</Salary>
      </Employee>

    </Employee>


The simplest possible solution is to load the XML into a DataSet and bind to that. Another solution would be to use XML serialization to create an object graph from the XML and bind to that. To bind to the raw XML, you would need to create wrapper classes that implement ITypedList, IBindingList, and ICustomTypeDescriptor.

Alternatively, you can try this..

 XmlReader xmlFile = XmlReader.Create("Xml_FilePath",new XmlReaderSettings());
 DataSet dataSet = new DataSet();

 dataSet.ReadXml(xmlFile);

 dataGridView1.DataSource = dataSet.Tables["Employees"];

 dataGridView1.DataBind();

1 comment:


  1. your ASP related concepts thus it is really well done to a great job thus it is nice too and i got more information from your blog. i like this article and it is very well good too to practice the concepts.


    Online Reputation Management

    ReplyDelete