方法
 private void DrpLst(string filename, string node, DropDownList obj, string s)
    {
        XmlDocument XmlDoc 
= new XmlDocument();
        
int i;
        XmlDoc.Load(Server.MapPath(filename));  
//filename是xml文件路徑
        XmlNode XmlRoot = XmlDoc.SelectSingleNode("data");
        XmlNode xmlNod 
= XmlRoot.SelectSingleNode(node); //node 是單個xml節點
        for (i = 0; i <= xmlNod.ChildNodes.Count - 1; i++)
        {
            ListItem li 
= new ListItem();
            li.Text 
= xmlNod.ChildNodes.Item(i).InnerText;
            li.Value 
= xmlNod.ChildNodes.Item(i).Attributes["value"].Value;
            
if (li.Value == s)
            {
                li.Selected 
= true;
            }
            obj.Items.Add(li);
//obj是dropdownlist控件
        }
    }

 

調用上面的方法:
 
 DrpLst("Applypro.xml""type", DrpLstType, "");

 

 

相关文章:

  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-09-25
  • 2022-01-22
  • 2021-05-23
猜你喜欢
  • 2022-01-21
  • 2021-07-31
  • 2022-02-06
  • 2022-12-23
  • 2021-10-02
  • 2021-07-11
  • 2022-12-23
相关资源
相似解决方案