Hi,
I have one xml file. That xml file have multiple elements. I want to read these elements and bind into datagrid using Linq in C#.
Hi,
I have one xml file. That xml file have multiple elements. I want to read these elements and bind into datagrid using Linq in C#.
You will probably be better served using DataTable/DataSet for this binding. But if you want to use LINQ 2 XML you could do something like this...
var xml = XElement.Load("yourfile.xml");
var records = from element in xml.Elements()
let col1 = element.Element("element1").Value
let col2 = element.Element("element2").Value
let col3 = element.Attribute("attribute1").Value
select new {
col1,
col2
col3
}
... note there are several spots where you could get NullReferenceExceptions in the above query.