Load xml file to xml dataset and bind to gridview in C#

In the method shown below, we will locate xml file within application, read it to a dataset and then set the xml dataset as datasource to grid view.

private void loadandbindXmlData()
{
    DataSet xmlData = new DataSet();
    xmlData.ReadXml(Server.MapPath(@"App_Data\myXmlFile.xml")); //locate xml file within application
    if (xmlData.Tables.Count > 0)
    {
        GVXmlData.DataSource = xmlData; //set xml dataset as datasource to grid view.
        GVXmlData.DataBind();
    }
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.