Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have written the code

one xml file

XML
<?xml version="1.0" encoding="utf-8"?>
<Interests>
  <Interest>
    <ID>1</ID>
    <Name>dance</Name>
  </Interest>
  <Interest>
    <ID>2</ID>
    <Name>Entertainment</Name>
  </Interest>
  <Interest>
    <ID>3</ID>
    <Name>Tours</Name>
  </Interest>
</Interests>



i pass the id and want to get the name

C#
string strBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
              string strFullPath = strBaseDirectory + "Interest.xml";

              string strid = Request.QueryString["Drop"];
              XElement xe = XElement.Load(strFullPath);
              var name = from Name in xe.Elements("Interest")
                         where (string)Name.Element("ID").Value == strid
                         select Name.Value;
              Label1.Text = name.Last().ToString();


but i got the result

1dance

but i need only "dance".

What I have tried:

linq to xml:

show value in a label.
Posted
Updated 24-Mar-16 2:58am
Comments
aiswarjya1 24-Mar-16 7:51am    
I have solved it

1 solution

Giving your variables better names might help! :)
C#
var name = from interest in xe.Elements("Interest")
    where (string)interest.Element("ID") == strid
    select (string)interest.Element("Name");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900