Deane
Deane

Reputation: 8747

Is there a non-iterating control that allows data-binding syntax to be used?

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?

Upvotes: 0

Views: 90

Answers (2)

ichiban
ichiban

Reputation: 6200

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

Upvotes: 1

RichardOD
RichardOD

Reputation: 29157

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.

Upvotes: 0

Related Questions