Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Can a repeater's ItemTemplate instantiate derived classes? (http://www.velocityreviews.com/forums/t779124-can-a-repeaters-itemtemplate-instantiate-derived-classes.html)

Big Daddy 10-26-2006 06:25 PM

Can a repeater's ItemTemplate instantiate derived classes?
 
I would like to have a repeater class like this:

<asp:Repeater ID="CriteriaRepeater" runat="server" >
<ItemTemplate>
<uc1:BaseControl ID="BaseControl1" BindData='<%#
Container.DataItem %>' runat="server" />
</ItemTemplate>
</asp:Repeater>

The thing that is getting repeated for each item in the datasource is a
user control that is a base class. I would like it to actually create
different controls that are devired from the base control, depending on
the values in the datasource. For example, if there are three classes
derived from BaseControl1 (DerivedControl1, DerivedControl2,
DerivedControl3), if the datasource has three records, the repeater
would be able to create one instance of each of the derived classes
rather than three instances of the base class. Is this possible?

Thanks in advance,
John


Phil H 10-29-2006 09:23 PM

Re: Can a repeater's ItemTemplate instantiate derived classes?
 
Dear John

In my opinion (for what it's worth) it is doubtful that the runtime is
that clever.

Any controls types that are created which can be handled by predefined
post-back events have to be declared explicitly in the template.

I will happlily be proved wrong but I came up against something similar
to this myself. I wanted to create link-button controls
programmatically in a DataList control or table. The trouble is that
you can't write event handlers on the fly at runtime. The solution for
me was to create hyperlinks in a table object that generated
Querystring parameters in the navigateUrl property.

If anyone knows a better way I'd be grateful and am sure a similar
technique would help John.

Phil Hall

Big Daddy wrote:
> I would like to have a repeater class like this:
>
> <asp:Repeater ID="CriteriaRepeater" runat="server" >
> <ItemTemplate>
> <uc1:BaseControl ID="BaseControl1" BindData='<%#
> Container.DataItem %>' runat="server" />
> </ItemTemplate>
> </asp:Repeater>
>
> The thing that is getting repeated for each item in the datasource is a
> user control that is a base class. I would like it to actually create
> different controls that are devired from the base control, depending on
> the values in the datasource. For example, if there are three classes
> derived from BaseControl1 (DerivedControl1, DerivedControl2,
> DerivedControl3), if the datasource has three records, the repeater
> would be able to create one instance of each of the derived classes
> rather than three instances of the base class. Is this possible?
>
> Thanks in advance,
> John




All times are GMT. The time now is 12:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57