Need help writing special user control

J

John Knoop

Hi all!

I would like to create a user control that handles an unlimited amount of
templates. I suppose I would like to define the templates kind of like this:

<mycontrol datakeyfield="model" id="ctl" runat="server">
<template key="Ferrari">
<h1><%# Container.DataItem("model") %></h1><br>
<font color="red">Some text</font>
</template>
<template key="Jaguar">
<h1><%# Container.DataItem("model") %></h1><br>
<font color="black">Some text</font>
</template>
<template key="Lamborghini">
<h1><%# Container.DataItem("model") %></h1><br>
<font color="blue">Some text</font>
</template>
</mycontrol>

How do I achieve this? I've tried to declare the Template property of the
usercontrol like this:

<TemplateContainer(GetType(MegaItem))> public Property Template(key as
object) As ITemplate

....but I can't seem to solve it.

Please help

/john
 
J

John Knoop

Hi

But will that let me use a number of different templates within the same
servercontrol? Plus, I would rather design the templates within tags on the
same page, than in files of their own.

/john
 
N

Natty Gur

Hi,

1) Yes:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
DataList1.DataSource = CreateDataSource();
DataList1.DataBind();
}
else
{
DataList1.AlternatingItemTemplate =
Page.LoadTemplate("b.ascx");
DataList1.DataSource = CreateDataSource();
DataList1.DataBind();
//DataList1.DataBind();
}
}

2) I'm not aware of other way, but I'll be happy to learn.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top