Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert - 19 Oct 2005 13:02 GMT
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
Curt_C [MVP] - 19 Oct 2005 13:57 GMT
Nope.
You can look at Nested Repeaters but afaik you can't have two <ItemTemplate>
sections in the same repeater.

Signature

Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

> Hi,
> if I create a class A with some properies, then create classes B and C
[quoted text clipped - 6 lines]
> Thank you very much.
> Robert
Karl Seguin - 19 Oct 2005 14:04 GMT
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
Signature

MY ASP.Net tutorials
http://www.openmymind.net/

> Hi,
> if I create a class A with some properies, then create classes B and C
[quoted text clipped - 7 lines]
> Thank you very much.
> Robert

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.