.net - Populating dropdown from the XML in C# -


i have got below xml format me , using .net 2.0.

<?xml version="1.0" encoding="utf-8"?> <publicationslist>   <publication tcmid="tcm:0-226-1">     <name>00 primary parent</name>   </publication>   <publication tcmid="tcm:0-227-1">     <name>01 group parent</name>   </publication>   <publication tcmid="tcm:0-228-1">     <name>02 developer library</name>   </publication>   <publication tcmid="tcm:0-229-1">     <name>03c content library</name>   </publication> </publicationslist> 

now want populate dropdownlist above xml, dropdownlist text "name" node value , dropdownlist value "tcmid" attribute value using method in c#.

please suggest!!

you this

using linq

xdocument xdoc = xdocument.load(@"yourxmlfile.xml");             var query = xele in xdoc.descendants("publication")                         select new listitem(xele.element("name").value, xele.attribute("tcmid").value);              ddllist.datavaluefield = "value";             ddllist.datatextfield = "text";             ddllist.datasource = query;             ddllist.databind(); 

update: using xmldocument

xmldocument xdocument = new xmldocument();             xdocument.load(@"yourxmlfile.xmll");             foreach (xmlnode node in xdocument.getelementsbytagname("publication"))             {                 ddllist.items.add(new listitem(node.selectsinglenode("name").innertext,                     node.attributes["tcmid"].value));             }             ddllist.datavaluefield = "value";             ddllist.datatextfield = "text";                         ddllist.databind(); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -