c# - Null reference using Linq to Xml -
i making country, state dropdownlist.
for eg: particular country, read states of country xml file below code
protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) { string st = (dropdownlist1.selectedindex).tostring(); xdocument main = xdocument.load((server.mappath(@"xmlfile1.xml"))); var query = user in main.descendants("country") st == user.element("state").value --//i getting error here object select user; reference not set instance object dropdownlist2.datasource = query; dropdownlist2.databind(); } op's xml (link provided in chuck's comments) : bind dropdownlist using xml
if using namespace in xml file following might you.:
xnamespace ns = "url";// url namespace path namespace var query = user in main.descendants("country") state in user.elements("state") state.value == "st" select user;
Comments
Post a Comment