Databinding templated controls exclusively from the code behind

A

AC [MVP MCMS]

Implementing databinding from the ASPX/ASCX file is very
straightforward:
<asp:XmlDataSource id="XmlDs1" DataFile="[some RSS feed]">...</>
<asp:Repeater>
<HeaderTemplate><%#XPath("title")%></>
</>

However, what if you wanted to do this ONLY from the code behind? For
example, if I didn't have a repeater on an ASPX page or anything... it
would be added dynamically. How you do you do something like this:

// bind XmlDataSource to a repeater
// create & add an ASP.NET HyperLink control to the HeaderTemplate of a
repeater that was added to the page.
someLink.NavigationUrl = "#XPath("title") ; // I know this won't
work, just trying to convey the concept

Is this even possible? I'm fairly certain it is, just keep hitting a
dead end and can't find any articles out there that demonstrate it.

TIA,
 
A

AC [MVP MCMS]

Eliyahu-
Thanks again, that article was spot on. However, I've got a question about binding with an XmlDataSource and using the XPath method.

Say, in markup, I create an XmlDataSource and set the DataFile to an RSS feed with no XPath defined. Then I associate it to a Repeater, and inside the Repeater, I have a <%# XPath("title") %> to fetch the title of the feed.

I'm having one heck of a time getting this to work in a 100% pure code behind model. I've tried numerous permutations with no success. Even obtaining a reference to the DataItem within my event handler returns an object that's not even listed in the SDK. ideas?
 
E

Eliyahu Goldin

Unfortunately, my experience with xml-related matters is rather limited.You
will get better response if you re-post it in a separate thread.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


AC said:
Eliyahu-
Thanks again, that article was spot on. However, I've got a question about
binding with an XmlDataSource and using the XPath method.

Say, in markup, I create an XmlDataSource and set the DataFile to an RSS
feed with no XPath defined. Then I associate it to a Repeater, and inside
the Repeater, I have a <%# XPath("title") %> to fetch the title of the
feed.

I'm having one heck of a time getting this to work in a 100% pure code
behind model. I've tried numerous permutations with no success. Even
obtaining a reference to the DataItem within my event handler returns an
object that's not even listed in the SDK. ideas?

--
-AC [MVP MCMS]
www.andrewconnell.com/blog


Eliyahu said:
xxxTemplate properties can be created in two ways. You can either load
them from external files

myRepeater.HeaderTemplate.LoadTemplate(fileName)

or you can use custom Template classes:

Creating Web Server Control Templates Dynamically
http://msdn.microsoft.com/library/d...atingwebservercontroltemplatesdynamically.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top