Tutorial :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?


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »