Creating templates programmaticaly from a repareater DataSource

P

Patrice Scribe

I would like to create templates using instantiatein depdepnding on the
current datasource.

Is this possible ? I do'nt see how I could access the datasource using the
container ?

Or should I do this at databind time (not too late ?)

TIA

--
 
T

Teemu Keiski

Hi,

You want to provde templates in code? In that case:

1. Create a method to build the child control hierarchy (templates from
datasource) and so that the method takes a parameter to indicate that is
data source to be used or not (say boolean=true for using datasource, false
not using). Method can be named CreateControlHierarchy for example. If True
is given in the argument, method creates control hierarchy (templates) from
the datasource (DataSource proeprty) and stores enough information to
ViewState or equivalent about the templates (count etc and type) so that
they can be recreated on non-databind request (just recreating them is
enough, other stuff is restored by ViewState) that is, when
CreateControlHierarchy is called with argument False.

2. Override Control's DataBind method and do following steps
-Call base class's OnDataBinding method
- call Controls.Clear()
- call ClearChildViewState()
-call TrackViewState()
-call CreateControlHierarchy(true) (to indicate that child controls are
built from datasource)
-Set "ChildControlsCreated=True"

3. Override CreateChildControls method:
-call Controls.Clear()
-call CreateControlHierarchy(false)

Idea here is that you set the DataSource for the control and call DataBind
when it is bound. As a result, control builds its hierarchy based on
datasource(templates and values into child controls of template from
datasource). On other requests, when DataBind is not called (control is not
databound) only CreateChildControls is called and just control hierarchy
(that is templates of correct types andsame count, not anything else) is
rebuilt. The actual data/values are restored by ViewState.
 
J

Jeffrey Tan[MSFT]

Hi Patrice,

Do you still have any concern?
If you have anything unclear, please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Patrice,

I found some additional references for you.

Developing a Templated Data-Bound Control
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopingtemplate
ddataboundcontrol.asp

Templated Data-Bound Control Sample
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontemplateddatabound
controlsample.asp

Developing a Templated Control
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomizingcontrol
swithtemplates.asp

Developing a Templated Control
http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#te
mplated

Developing a Templated Databound Control
http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#te
mplatedlist

If you have any concern, please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top