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

Need Help with a repeater and web custom control

P: n/a
I am having a hard time with makeing what I am trying to do work. I
am making a questionaire web app. I have a custom control that has a
label and 5 radio buttons. My problem is that each different topic
for the questionaire is in a database and each questionaire will have
a different number of questions. I am trying to use a repeater to
creat multiple copies of the control, unfortunately when I do this the
different controls act like thay are the same. Can anyone give me a
way to do what I am trying? Thanks alot

Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can use the ItemDataBound event to set a property value in the
RepeaterItem that you can retrieve when processing on PostBack.

While you don't say much about how you're using the repeater or accessing
the User Controls, a common method is to assign a value to the
CommandArgument property of a Button in your RepeaterItem from within the
ItemDataBound event handler. Then, in your event handler for ItemCommand,
you can test the value of the CommandArgument or for whatever other property
you set in your ItemDataBound handler. If your Button exists in the User
Control then just expose the Button's CommandArgument property through the
User Control.

Also, if you use the ItemCommand event to trigger your processing, you can
access the specific User Control instance by using something like this:

MyUserControl myControl =
(MyUserControl)e.Item.Controls[indexOfUserControl];

That would give you access to the individual User Control.

Don't make the mistake of using Item.Index to establish which item was
clicked or which item you're responding to in your PostBack processing. If
the database has changed then the contents of your Repeater.DataSource may
not be the same in PostBack as they were initially.

HTH

DalePres
MCAD, MCDBA, MCSE
<an**@anon.com> wrote in message
news:ce********************************@4ax.com...
I am having a hard time with makeing what I am trying to do work. I
am making a questionaire web app. I have a custom control that has a
label and 5 radio buttons. My problem is that each different topic
for the questionaire is in a database and each questionaire will have
a different number of questions. I am trying to use a repeater to
creat multiple copies of the control, unfortunately when I do this the
different controls act like thay are the same. Can anyone give me a
way to do what I am trying? Thanks alot

Nov 16 '05 #2

P: n/a
Thanks, that helped. To answer how it is being used, I have a control
that is 5 radiobuttons. This control is going to be placed for each
question in a questionaire. I want to use the repeater to put the
control on the page as many times as is needed. each Questionaire has
a different number of questions and a dropdown list is how the user
selects which questionaire to use
On Sat, 12 Mar 2005 11:20:03 -0600, "DalePres"
<don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote:
You can use the ItemDataBound event to set a property value in the
RepeaterItem that you can retrieve when processing on PostBack.

While you don't say much about how you're using the repeater or accessing
the User Controls, a common method is to assign a value to the
CommandArgument property of a Button in your RepeaterItem from within the
ItemDataBound event handler. Then, in your event handler for ItemCommand,
you can test the value of the CommandArgument or for whatever other property
you set in your ItemDataBound handler. If your Button exists in the User
Control then just expose the Button's CommandArgument property through the
User Control.

Also, if you use the ItemCommand event to trigger your processing, you can
access the specific User Control instance by using something like this:

MyUserControl myControl =
(MyUserControl)e.Item.Controls[indexOfUserControl];

That would give you access to the individual User Control.

Don't make the mistake of using Item.Index to establish which item was
clicked or which item you're responding to in your PostBack processing. If
the database has changed then the contents of your Repeater.DataSource may
not be the same in PostBack as they were initially.

HTH

DalePres
MCAD, MCDBA, MCSE
<an**@anon.com> wrote in message
news:ce********************************@4ax.com.. .
I am having a hard time with makeing what I am trying to do work. I
am making a questionaire web app. I have a custom control that has a
label and 5 radio buttons. My problem is that each different topic
for the questionaire is in a database and each questionaire will have
a different number of questions. I am trying to use a repeater to
creat multiple copies of the control, unfortunately when I do this the
different controls act like thay are the same. Can anyone give me a
way to do what I am trying? Thanks alot

Nov 16 '05 #3

P: n/a
Well, sounds like you may have it solved by now, but just in case:

Since your data isn't going to change between round trips, and you don't
have a button on any given RepeaterItem, when the user submits the form, all
you have to do is loop through the Repeater.Items collection like this:

foreach (RepeaterItem item in MyRepeater.Items)
{
MyUserControl myUserControl =
(MyUserControl)item.Controls[userControlIndex];
// do some stuff with myUserControl
}

DalePres

<an**@anon.com> wrote in message
news:p9********************************@4ax.com...
Thanks, that helped. To answer how it is being used, I have a control
that is 5 radiobuttons. This control is going to be placed for each
question in a questionaire. I want to use the repeater to put the
control on the page as many times as is needed. each Questionaire has
a different number of questions and a dropdown list is how the user
selects which questionaire to use
On Sat, 12 Mar 2005 11:20:03 -0600, "DalePres"
<don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote:
You can use the ItemDataBound event to set a property value in the
RepeaterItem that you can retrieve when processing on PostBack.

While you don't say much about how you're using the repeater or accessing
the User Controls, a common method is to assign a value to the
CommandArgument property of a Button in your RepeaterItem from within the
ItemDataBound event handler. Then, in your event handler for ItemCommand,
you can test the value of the CommandArgument or for whatever other
property
you set in your ItemDataBound handler. If your Button exists in the User
Control then just expose the Button's CommandArgument property through the
User Control.

Also, if you use the ItemCommand event to trigger your processing, you can
access the specific User Control instance by using something like this:

MyUserControl myControl =
(MyUserControl)e.Item.Controls[indexOfUserControl];

That would give you access to the individual User Control.

Don't make the mistake of using Item.Index to establish which item was
clicked or which item you're responding to in your PostBack processing.
If
the database has changed then the contents of your Repeater.DataSource may
not be the same in PostBack as they were initially.

HTH

DalePres
MCAD, MCDBA, MCSE
<an**@anon.com> wrote in message
news:ce********************************@4ax.com. ..
I am having a hard time with makeing what I am trying to do work. I
am making a questionaire web app. I have a custom control that has a
label and 5 radio buttons. My problem is that each different topic
for the questionaire is in a database and each questionaire will have
a different number of questions. I am trying to use a repeater to
creat multiple copies of the control, unfortunately when I do this the
different controls act like thay are the same. Can anyone give me a
way to do what I am trying? Thanks alot


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.