Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filling a Drop down from an XML
Message
From
14/01/2011 07:13:48
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01496032
Message ID:
01496135
Views:
28
>>I had tried to use a linq version withou success such as this.
>>
>>XmlDocument doc = new XmlDocument();
>>doc.Load(Server.MapPath("/Xml/States.xml"));
>>
>>for (int i = 0; i < 50; i++)
>>{
>>this.cboState.Items.Add(new Telerik.Web.UI.RadComboBoxItem(doc.SelectNodes("/states/state[i]/name").ToString(), doc.SelectNodes("/states/state[i]/Id").ToString()));
>>}
>>
Don't like that. What if Texas pulls out of the union. :-} How about:
foreach (XmlElement x in doc.SelectNodes("/states/state"))
>            {
>                someComboBox.Items.Add(x.GetAttribute("Name"));
>            }
>When I use the code you show I get several errors on the syntax checker.
>>red line under f on from indicates Unknown method 'Select(?)' of System.Collections.Generic.IEnumerable(System.Xml.Linq.XElement)'
>>and on the state variables it indicates (range variable) TRow state is Unknown type of variable 'state'
>
>Just checked and the code worked for me with your first version of the states.xml (using attributes)
>Sounds as if maybe you don't have a reference to System.Linq in your usings....
>HTH

Hi Viv,

It took me a bit to figure out why the comment about Texas but now I see I had used 50 in my for count as a quick test. I suppose if that had worked I can only hope I would have remembered to do that different before accepting it. :-)

This last solution worked by referencing "Element.Attribute" which means it boils down to how the xml is constructed. Nodes versus attributes of a node. This is the first time I have tried to use Xml like this.
Thanks for your help. A bunch!
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform