日期:2014-05-20  浏览次数:20849 次

xml 问题!跪求,急啊!
我的xml文件 <?xml version="1.0" encoding="utf-8" ?>
<CommonTypes> //xml文件名ttt.xml
  <Types Name="IDocType">
  <Type ID="01">原件</Type>
  <Type ID="02">复印件</Type>
  <Type ID="03">电子图</Type>
  </Types>
</CommonTypes>


怎样在后台代码 给 DropDownList 负值!
public void DropDownListDateBing()
  {
  ArrayList dropdownlist;
  ...........
  ............
  }

------解决方案--------------------

C# code

     protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadXmlFile();
        }
        
    }

    public void LoadXmlFile()
    {      
        string path = Server.MapPath("XML/test.xml");  //这里是你文件路径

        XmlDocument doc = new XmlDocument();
        doc.Load(path);

        XmlNodeList nodeList = doc.SelectNodes("CommonTypes/Types/Type");
        foreach (XmlNode node in nodeList)
        {
            ListItem li = new ListItem(node.InnerText,node.Attributes["ID"].Value);
            DropDownList1.Items.Add(li);  //DropDownList1是ID
        }
    }