System.Web.UI.WebControls.Repeater and multiple templates

R

Robert

Hi,
if I create a class A with some properies, then create classes B and C
derived from A, later create and ArrayList filled with some B and C items.
This list I would like to use as a datasource for a repeater control. Is it
possible to add more than one <ItemTemplate>? I would like to have i.e two
templates, one for B and second for C object.
I'm using ASP.NET (2.0) very shortly, but I haven't discovered much about
Repeater/Datalist/Datagrid.
Thank you very much.
Robert
 
G

Guest

Nope.
You can look at Nested Repeaters but afaik you can't have two <ItemTemplate>
sections in the same repeater.
 
K

Karl Seguin

No.

What you can do is have a single item template with a placeholder

<ITemTemplate>
<asp:placeHolder id="content" runat="server" />
</ItemTemplate>


Then, in the ItemDataBound event, check which type your DataItem is, and
load the appropriate user control.

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
PlaceHolder content = (PlaceHolder)e.Item.FindControl("content");
if (e.Item.DataItem is B)
{
...
}else...

}

you can learn more from
http://openmymind.net/index.aspx?documentId=8#4.2

Karl
 

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

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top