By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Repeater Contains Web User Control

P: n/a
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

Oct 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

--
http://www.openmymind.net/
http://www.codebetter.com/
"Webmills" <ja***@instantecommerce.co.ukwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
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

Oct 18 '06 #2

P: n/a
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.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Webmills" <ja***@instantecommerce.co.ukwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
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

Oct 18 '06 #3

P: n/a
Thanks all, much obliged.

Oct 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.