Repeater Contains Web User Control

W

Webmills

Hi all

I have a repeater control containing a web user control within its'
item template field.

Is it possible to pass through a data field into the web user control,
such that this is used when rendering the web user control.

I have exposed a parameter of the web user control and attempted to
pass in the parameter as below:

<MyUserControl:Booking_Details runat="server" EventId='<%#
(int)(Eval("fId")) %>' />

However, the control is rendered before the set accessor is called.

Is this possible to do, or am I missing something really obvious.

Thanks

James
 
K

Karl Seguin [MVP]

do it through the ItemDataBound event of the repeater...

if the ItemType is Item or AlternatingItem, find the user control:

BookingDetails bd = (BookingDetails)e.Item.FindControl("userControlId");
bd.EventId = (int)((DataRowView)e.DataItem)["fId"];

assuming you are binding to a dataset/datatable/dataview...

Karl
 
M

Mark Fitzpatrick

James,
You could, instead of doing it this way, add an event handler for
the itemdatabound event of the repeater. Then, you can use the
e.Item.FindControl method to find a reference to your web user control. An
example using a label is:

Label myLabel = (Label)e.Item.FindControl("myLabel");

Of course, instead of a Label you'll use the type of your usercontrol. Once
found, test to ensure that the variable isn't null first, then you should be
able to set the event id base on the repeater control's data item. The
dataitem will be a DbDataRecord and you can access it like so:

DbDataRecord record = (DbDataRecord)e.Item.DataItem;

then use it in a similar fashion to a datareader. You may have to tweak some
of the timings in the web user control to get it right as some page events
often used to setup a repeater's data, such as the Page_Load, occur after
these events in the web user control, hence why in the web user control a
lot of people use the prerender event to do processing to ensure that the
properties can be set from the parent page.
 

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,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top