473,395 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Databinding templated controls exclusively from the code behind

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,

--
-AC [MVP MCMS]
www.andrewconnell.com/blog
Dec 31 '06 #1
4 3751
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/de...ynamically.asp

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"AC [MVP MCMS]" <sw*********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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,

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

Jan 1 '07 #2
This is _exactly_ the article I was looking for. Thanks Eliyahu!
--
-AC [MVP MCMS]
www.andrewconnell.com/blog
Eliyahu Goldin wrote:
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/de...ynamically.asp
Jan 2 '07 #3
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 Goldin wrote:
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/de...ynamically.asp
Jan 4 '07 #4
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 [MVP MCMS]" <sw*********@gmail.comwrote in message
news:e9**************@TK2MSFTNGP03.phx.gbl...
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 Goldin wrote:
>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/de...ynamically.asp

Jan 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted...
2
by: Steve Black | last post by:
Hello, I am dynamically creating checkboxes on my web page based on data in a SQL Server table. Therefore, these checkboxes do not exist at design time and I cannot refer to them in my...
2
by: Oleg | last post by:
Let's say I rendered a bunch of controls with the same name and different IDs. On postback, can I somehow iterate through these controls (checkboxes in this case, but could be dropdown controls in...
3
by: Roshawn Dawson | last post by:
Hi, Suppose I have an form that contains any number of controls. To access these controls programatically and get/set the state of their properties, must they all be server controls (have the...
2
by: Charlie | last post by:
Hi: The new databound controls (GridView, DetailsView, ect.) use declaritive syntax (i.e, setup in HTML at design time). However, at times sql statements and parameters may need to be derived...
4
by: viveklinux | last post by:
Hi , I have a table which needs to be populated at runtime. Is there a way to do this without using a server side control like repeater or datagrid ? How can an HTML control be accessed in code...
3
by: David A. Osborn | last post by:
I have a web project inVS2005 that I copied some existing pages from a website that I previously created. To clarify the website was originally created in Visual Web Developer Express and not I...
4
by: Charlie Bear | last post by:
hi, i'm running visual studio 2005 working on asp.net projects. Suddenly visual studio has stopped automatically adding controls to the designer code behind. anyone know why or how to fix it? i...
1
by: bernie77 | last post by:
Originally, I have the a panel with a drop down list and a radio button list (2 controls). Now user requests the capability to dynamically show the second control depending on user selection in the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.