Error loading contents from a XML file into a dropdownlist
Posted
by Chaitanya
on Stack Overflow
See other posts from Stack Overflow
or by Chaitanya
Published on 2010-04-05T07:31:49Z
Indexed on
2010/04/05
7:33 UTC
Read the original article
Hit count: 446
private void BindCountry()
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("countries.xml"));
foreach (XmlNode node in doc.SelectNodes("//country"))
{
usrlocationddl.Items.Add(new ListItem(node.InnerText, node.Attributes["codes"].InnerText));
//ddlCountry.Items.Add(new ListItem(node.InnerText, node.Attributes["code"].InnerText));
}
}
The above code am using for loading countries List from an xml file into a dropdown list. But while doing so am encountering a Null Reference error.
Object reference not set to an instance of an object.
Where in the code should I be changing, so that I can escape the error.
© Stack Overflow or respective owner