Home > Code > LINQ > Reading XML file using LINQ and bind to Gridview

Reading XML file using LINQ and bind to Gridview

by Narain Siddharth   on Apr 30, 2011   Category: LINQ   |  Views: 5210    |  Points: 25   |  Silver 


Below sample code used to read the xml file using simple LINQ and binding to gridview.

xml file

<?xml version="1.0" encoding="utf-8" ?> 
<technologies>
<languages>
<name>ASP.NET</name>
<url>www.asp.net</url>
</languages>
<languages>
<name>C#.NET</name>
<url>www.asp.net</url>
</languages>
<languages>
<name>J#.NET</name>
<url>www.asp.net</url>
</languages>
<languages>
<name>SQL SERVER</name>
<url>www.asp.net</url>
</languages>
</technologies>


C# Code

XDocument xmlDoc = XDocument.Load(@"D:\mytech.xml");
var vrresult = from a in xmlDoc.Descendants("languages")
select new
{
TECNOLOGIES = a.Element("name").Value,
URL = a.Element("url").Value
};
GvTechnology.DataSource = vrresult;
GvTechnology.DataBind();


Regards,
Narain.




Post Code  |  Code Snippet Home

User Responses


  Re :Reading XML file using LINQ and bind to Gridview   
Posted by Shiva
on 03/05/2011
Points : 5

Useful code. please post more code snippets on LINQ.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts