views:

46

answers:

2

Let's say I have a single XML node of content in my code-behind. I need to get some data out of the various nodes and onto a Web form.

Traditionally, I would create a bunch of Literals on the page, then do stuff like this in the code-behind:

MyLiteral.Text = myXmlNode.SelectSingleNode("/some/xpath").InnerText;

This is fine and good, but consider the binding syntax we use in Repeaters:

<ItemTemplate>
    <p>
        <%# XPath("/some/xpath") %>
    </p>
</ItemTemplate>

So, I got to wondering if you can use this same syntax for non-Repeater situations. It just seems odd that there wouldn't be the same syntax available for a non-iterating situation.

(Of course, if you didn't mind being ridiculous, you could bind your XML node to a Repeater, where it would only have one iteration. I swear I've never done this...)

I can't help but thinking that the designers of the framework would have planned for this. Is there some non-iterating control I don't know about that allows you to bind a datasource and render using data binding expressions?

A: 

The best suggestion I can think of, is using something like the DetailsView or FormView. This will at least get rid of the issue of having "non repeating" data.

RichardOD
+1  A: 

As you have already discovered that databinding syntax only works with composite controls, such as repeaters, listviews, detailsView, etc.

ichiban
Sad. There should be a "BindableRegion" control or something.
Deane