Friday, January 23, 2009

Linq to XML with Join Query

The Screenshot of FactoryOutLet.xml is

The Screenshot of Factory.xmlAfter Creating two XML Paste the following code on Page_Load Event

var query = from m in XElement.Load(MapPath("FactoryOutlet.xml")).Elements("Garment")
join g in XElement.Load(MapPath("Factory.xml")).Elements("Factory")
on (string)m.Element("Name") equals (string)g.Element("Name")
select new
{
Shirt=(string)m.Element("Shirt"),
Pent=(string)m.Element("Pent"),
Sweater=(string)m.Element("Sweater"),
Shoes=(string)m.Element("Shoes"),
Belt=(string)m.Element("Belt"),
Name=(string)m.Element("Name")
};
gvFactoryOutlet.DataSource = query;
gvFactoryOutlet.DataBind();

The Screenshot of after running a Particular Page




No comments:

Post a Comment