Populate DropDownList from XmlDataSource

后端 未结 3 664
囚心锁ツ
囚心锁ツ 2021-01-21 20:06

I\'d like to populate my DropDownList using a simple xml file:



  foo         


        
3条回答
  •  耶瑟儿~
    2021-01-21 20:26

    Here is one way of doing it - you can project an array of ListItems in a LINQ query:

    XDocument doc = XDocument.Parse(@"
            foo
            bar
            baz
        ");
    
    YourList.Items.AddRange(
        (from XElement el in doc.Descendants("Database")
        select new ListItem(el.Value)).ToArray()
    );
    

提交回复
热议问题