User controls in DataList

A

Amil Hanish

I want to create a bunch of like user controls and display them in a
DataList.

Does anyone have a GOOD example of how to do this?

I thought I had it...I added the user control to my <ItemTemplate>, created
an array of user controls in my code behind and set the DataSource and
called DataBind. But, all the user controls are unitialized when the page
is rendered.

Amil
 
R

Riki

Amil said:
I want to create a bunch of like user controls and display them in a
DataList.

Does anyone have a GOOD example of how to do this?

I thought I had it...I added the user control to my <ItemTemplate>,
created an array of user controls in my code behind and set the
DataSource and called DataBind. But, all the user controls are
unitialized when the page is rendered.

Amil

Just put the user control in the template like you would do with any other
control (e.g. a textbox).
Bind the properties of the user control that you need.

The DataList will create the "array" of user controls automatically.

The setup of the user control should be done by the user control itself as
soon as its properties are assigned.
Whether it is in a template, or just in a page by itself, should not make a
difference.
 
A

Amil Hanish

Ahh...I think I've got it. I was creating my own array, but so was
asp.net...that's the reason all my objects were not initialized...they were
asp.net's objects (not the ones I created).

It's sort of a complex algorithm to set the user control properties. Can I
call a protected method from the datalist <ItemTemplate>, passing it the
asp.net object, and then let my method set the specific values?

Thanks.

Amil
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top