stevesuch
asked on
CDATA dropdownlist binding
Hi, I'm trying to bind xml to a dropdownlist I have, but am having trouble setting the CDATA child element as the DataTextField:
The xml is as follows:
<?xml version="1.0" encoding="utf-16"?>
<content>
...
<contentblock id="OrderStatus">
<contentitem id="0" type="1" local="True"><![CDATA[Canc elled]]></ contentite m>
<contentitem id="1" type="1" local="True"><![CDATA[Inco mplete]]>< /contentit em>
</contentblock>
...
</content>
The controls read as follows:
<asp:XmlDataSource ID="XmlDataSource1" Runat="server" DataFile="App_Data\transla tions\en\g lobal.xml"
XPath="content/contentbloc k[@id ='OrderStatus']/contentite m">
</asp:XmlDataSource>
<asp:DropDownList runat="server" DataSourceID="XmlDataSourc e1" AutoPostBack="true" Width="90" ID="lstStatus" DataValueField="id"
DataTextField="."></asp:Dr opDownList >
I've tried "/", "/text()", "CDATA" but they all return:
XmlDataSourceNodeDescripto r' does not contain a property with the name "." or whatever I try in DataTextField.
Any help would be greatly appeciated. Cheers
The xml is as follows:
<?xml version="1.0" encoding="utf-16"?>
<content>
...
<contentblock id="OrderStatus">
<contentitem id="0" type="1" local="True"><![CDATA[Canc
<contentitem id="1" type="1" local="True"><![CDATA[Inco
</contentblock>
...
</content>
The controls read as follows:
<asp:XmlDataSource ID="XmlDataSource1" Runat="server" DataFile="App_Data\transla
XPath="content/contentbloc
</asp:XmlDataSource>
<asp:DropDownList runat="server" DataSourceID="XmlDataSourc
DataTextField="."></asp:Dr
I've tried "/", "/text()", "CDATA" but they all return:
XmlDataSourceNodeDescripto
Any help would be greatly appeciated. Cheers
Have you tried it without the CDATA code, just using the text you want to display?
The DataTextField attribute is looking for an attribute in the XML file. It looks like you cannot use the contents of the node, it has to be like this:
<contentblock id="OrderStatus">
<contentitem id="0" type="1" local="True" text="Cancelled" />
<contentitem id="1" type="1" local="True" text="Incomplete" />
</contentblock>
And then set DataTextField to "text"
<contentblock id="OrderStatus">
<contentitem id="0" type="1" local="True" text="Cancelled" />
<contentitem id="1" type="1" local="True" text="Incomplete" />
</contentblock>
And then set DataTextField to "text"
ASKER
Ahh damn it. The problem is there's special characters in the string that can't be processed in just a standard attibute and need to be wrapped in a CDATA tag, on top of that the xml document is in a fixed format from the client and cannot be changed. Is there no way of setting it to a childnode in the code behind?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks ChetOS82, I've written my own