Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <pre><code>&lt;%@ Page Language="C#" %&gt; &lt;script runat="server"&gt; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string xml = @"&lt;?xml version=""1.0"" encoding=""utf-8"" ?&gt; &lt;Databases&gt; &lt;Database name=""foo"" /&gt; &lt;Database name=""bar"" /&gt; &lt;Database name=""baz"" /&gt; &lt;/Databases&gt;"; databasesSource.Data = xml; databasesSource.DataBind(); } } &lt;/script&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head runat="server"&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:DropDownList ID="databases" runat="server" DataSourceID="databasesSource" DataValueField="name" DataTextField="name" /&gt; &lt;asp:XmlDataSource ID="databasesSource" runat="server" XPath="/Databases/Database" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Note that I added the <em>name</em> attribute instead of using the value of the node directly.</p> <p>If you can't modify the structure of your original XML file you can apply an XSLT transformation on it using the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.transformfile.aspx" rel="noreferrer">TransformFile</a> property as described in this <a href="http://weblogs.asp.net/rajbk/pages/431322.aspx" rel="noreferrer">post</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload