Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
XML
<stat>
  <state>
    <stateid>102</stateid>
    <statename>ajmer</statename>
  </state>
  <state>
    <stateid>102</stateid>
    <statename>kota</statename>
  </state>
  <state>
    <stateid>103</stateid>
    <statename>sikar</statename>
  </state>
  <state>
    <stateid>103</stateid>
    <statename>Bikaner</statename>
  </state>
</stat>


C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
      string st = (DropDownList1.SelectedItem.Value).ToString();

      XDocument main = XDocument.Load(Server.MapPath(@"~\XMLFile.xml"));


      var query = from user in main.Descendants("state")
                  where st == user.Element("stateid").Value
                  select user;

      DropDownList2.DataSource = query;
      DropDownList2.DataTextField = "statename";
      DropDownList2.DataBind();
  }

my result is coming like this in dropdown as simple its not filtering
<state><stateid>102</stateid><statename>ajmer</statename></state>

<state><stateid>102</stateid><statename>kota</statename></state>

and i want to show simple ajmer and kota in dropdown
Posted
Updated 2-Dec-13 23:52pm
v2

1 solution

Please chanege your LINQ query as below

SQL
var query = from user in main.Descendants("state")
                       where st == user.Element("stateid").Value
                       select user.Element("statename").Value;


it will work
 
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