Null reference using Linq to Xml

adt90

New Member
I am making Country, state dropdownlist.for eg: For particular country, i will read states of that country from XML file below is my code\[code\]protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string st = (DropDownList1.SelectedIndex).ToString(); XDocument main = XDocument.Load((Server.MapPath(@"XMLFile1.xml"))); var query = from user in main.Descendants("country") where st == user.Element("state").Value --//i am getting an error here like object select user; reference not set to an instance object DropDownList2.DataSource = query; DropDownList2.DataBind(); }\[/code\]OP's XML (link provided in Chuck's comments) : bind dropdownlist using XML
 
Back
Top