Need Help with a repeater and web custom control

  • Thread starter Thread starter anon
  • Start date Start date
A

anon

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
 
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
 
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


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


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
 
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

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


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


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
 
Back
Top