Linq to xml

Posted by Klbaiju under Regular Expressions on 10/2/2009 | Views : 1777 | Status : [Member] | Replies : 1
Hi this is for binding xml file to a gridview.
i used this code in load event.it is working.
i want to write this in a function.
ie if i enter name in a textbox and enter the button the corresponding city and age should be displayed.




XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
var persons = from person in xmlDoc.Descendants("Person")
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
Age = person.Element("Age").Value,
};

GridView1.DataSource = persons;
GridView1.DataBind();


i tried this type

public string bind(string ename)
{

XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
var persons = from person in xmlDoc.Descendants("Person") where name==ename
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
Age = person.Element("Age").Value,
};
return persons;

}

how it possible

Regards
K L BAIJU




Responses

Posted by: Sagarp on: 1/15/2010 [Member] Bronze

Up
0
Down
serch xml node

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response