LINQ using XML data load to combobox.

Posted by senthil | 8:40:00 PM | , , | 0 comments »

To use LINQ to XML you will need to import a two of namespaces.

using System.Linq;
using System.Xml.Linq;


private void StudentsLoad()
{
  var xElem = XElement.Load(@"Student.xml");

  var students = from prod in xElem.Descendants("Student")
           orderby prod.Element("StudentName").Value
           select prod.Element("StudentName").Value;

  lstStudents.DataContext = students;
}

0 comments

Related Posts Plugin for WordPress, Blogger...