I’d like to populate my DropDownList using a simple xml file:
<?xml version='1.0' encoding='utf-8' ?> <Databases> <Database>foo</Database> <Database>bar</Database> <Database>baz</Database> </Databases>
My XPath is
/Databases/Database
My drop down list is rendered as:
<select name='databaseDropDownList' id='databaseDropDownList'> <option selected='selected' value='System.Web.UI.WebControls.XmlDataSourceNodeDescriptor'>System.Web.UI.WebControls.XmlDataSourceNodeDescriptor</option> <option value='System.Web.UI.WebControls.XmlDataSourceNodeDescriptor'>System.Web.UI.WebControls.XmlDataSourceNodeDescriptor</option> <option value='System.Web.UI.WebControls.XmlDataSourceNodeDescriptor'>System.Web.UI.WebControls.XmlDataSourceNodeDescriptor</option> </select>
How should I extract the text?
Thanks
I can’t recall it from the top of my head but I think there was a bug in XmlDataSource that prevents you to bind to values of xml nodes. It works with attributes only. Please correct me if I am wrong with this. There’s a slight modification you need to make to your XML file:
Note that I added the name attribute instead of using the value of the node directly.
If you can’t modify the structure of your original XML file you can apply an XSLT transformation on it using the TransformFile property as described in this post.