2

I have a repeater control that pulls back some data from a database and creates a radiobuttonlist for values related to each row. I don't know how many rows will be coming back, so I don't know how many radiobuttonlists there will be. This repeater is inside of a form, and once I click "Submit" on the form I need to get the values from the radiobuttons generated by the repeater.

Any thoughts on how to do this?

1 Answer 1

4

There are a few options.

One is to use a nested Repeater to display the RadioButtons.

The other is to create the controls during the original repeaters. Repeater.ItemDataBound event.

In either case, you need to be very aware of the Page Lifecycle.

You'll want to avoid databinding in the Page_Load event, unless the databinding is being done with an if(!Page.IsPostback) block. If you fail to check for postback, you'll run into issues where the Page_Load calls a DataBind() call that then wipes the values of the repeater before any event handlers can use it.

Alternatively, you can do your binding in Page_Init, which occurs BEFORE the viewstate can be applied, so you won't lose your values.

You can also use USer Controls for the RadioButtons. There's a previous post that covers how to use nexsted user controls within a Repeater here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - ended up solving the problem a different way - created a custom radiobuttonlist control that could store information related to the row, then added the code for it to "do stuff" into the onselectedindexchanged event. This seems to work quite well for me. Nested repeaters would have been good too though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.