Link to home
Start Free TrialLog in
Avatar of stevesuch
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[Cancelled]]></contentitem>
  <contentitem id="1" type="1" local="True"><![CDATA[Incomplete]]></contentitem>
</contentblock>
...
</content>

The controls read as follows:

<asp:XmlDataSource ID="XmlDataSource1" Runat="server" DataFile="App_Data\translations\en\global.xml"
            XPath="content/contentblock[@id ='OrderStatus']/contentitem">
        </asp:XmlDataSource>
        <asp:DropDownList runat="server" DataSourceID="XmlDataSource1" AutoPostBack="true" Width="90" ID="lstStatus" DataValueField="id"
            DataTextField="."></asp:DropDownList>

I've tried "/", "/text()", "CDATA" but they all return:
XmlDataSourceNodeDescriptor' does not contain a property with the name "." or whatever I try in DataTextField.
Any help would be greatly appeciated. Cheers
Avatar of ChetOS82
ChetOS82
Flag of United States of America image

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"
Avatar of stevesuch
stevesuch

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
Avatar of ChetOS82
ChetOS82
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks ChetOS82, I've written my own