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));
}
}
上面的代码用于将 xml 文件中的国家列表加载到下拉列表中。但这样做时遇到空引用错误。
你调用的对象是空的。
xml文件的内容:
<countries>
<country code="AF" iso="4">Afghanistan</country>
<country code="AL" iso="8">Albania</country>
</countries>
我应该在代码中的哪个位置进行更改,以便我可以逃避错误。