///读取并遍历XML文件并绑定到下拉框
public void bind_ddshi()
{L_shi.Items.Clear();
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(Server.MapPath(".") + "/XMLConfig/region_name.xml");
}
catch
{
return;
}
XmlNodeList nodeList = xmlDoc.SelectNodes("datalist/region");
if (nodeList != null && nodeList.Count > 0)
{
foreach (XmlNode node in nodeList)
{
ListItem listtemp = new ListItem(node.Attributes["region_name"].Value,node.Attributes["region_name"].Value);
L_shi.Items.Add(listtemp);
}
}
}
XML文件如下:
<datalist> <region region_name="全部"> </region> <region region_name="哈尔滨"> </region> <region region_name="齐齐哈尔"></region> <region region_name="牡丹江"></region> <region region_name="佳木斯"></region> <region region_name="大庆"> </region> <region region_name="绥化"></region> <region region_name="鸡西"></region> <region region_name="鹤岗"></region> <region region_name="双鸭山"> </region> <region region_name="伊春"></region> <region region_name="七台河"></region> <region region_name="黑河"></region> <region region_name="大兴安岭"> </region> </datalist>
原文链接:https://www.f2er.com/xml/299624.html