473,672 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding templated controls exclusively from the code behind

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

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.Naviga tionUrl = "#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 3758
xxxTemplate properties can be created in two ways. You can either load them
from external files

myRepeater.Head erTemplate.Load Template(fileNa me)

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*********@gm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Implementing databinding from the ASPX/ASCX file is very
straightforward :
<asp:XmlDataSou rce id="XmlDs1" DataFile="[some RSS feed]">...</>
<asp:Repeater >
<HeaderTemplate ><%#XPath("titl e")%></>
</>

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.Naviga tionUrl = "#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.Head erTemplate.Load Template(fileNa me)

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.Head erTemplate.Load Template(fileNa me)

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*********@gm ail.comwrote in message
news:e9******** ******@TK2MSFTN GP03.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.Hea derTemplate.Loa dTemplate(fileN ame)

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
5308
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 user controls. Worse I'm trying to add dynamic user controls from within a repeater loop (looping through attributes)... I bind to a function in the code behind and pass in the attribute. <asp:repeater id="rAttributes" Runat="server">
2
4421
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 server-side code at design time. Once the page is submitted, how can I access these checkboxes in my code-behind? Thanks for the help,
2
1942
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 the future) and get their values and IDs with all this done in the code behind page? A small example would be appreciated. Thanks, Oleg
3
1167
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 runat="server" attribute)? Thanks, Roshawn
2
1708
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 at runtime. In ASP 1.0 we could do this in code behind, but how do we do it in ASP 2.0? The examples I see are setting up controls compeletly at design time. Thanks, Charlie
4
8668
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 behind ? Thanks in advance ..
3
3559
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 have created a web project (not a website) in VS2005 and add a few of the pages to this web project One of the pages I am currently working with is not allowing me to reference the controls from the design page in the code behind. Do I need to make...
4
1817
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 can add them manually but that is annoying.
1
1857
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 first control (drop down list). Sometimes the 2nd control can be a radiobuttonlist, sometimes the 2nd control can be another dropdownlist. How can I use code behind (in C#) to display the appropriate control at proper place of the panel? Any...
0
8418
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8696
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7466
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6254
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2836
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1834
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.