I would like to place a radiobuttonlist inside of a gridview cell. The
gridview is using a iList as it's datasource. In that gridview, in the
second column i have a itemtemplate that holds a radiobuttonlist. I need to
change the radiobuttonlist to not hold static listitem values and text

The iList that the radiobuttonlist will be bound to is called
oSurveyAnswerKeys with the property of RadioButtonText being the text adn
ValueSavedToDb as the value.

All the radiobuttonslist through the column will be identical for each row.
The need to be data driven because depending on the data passed to the
gridview, the radiobuttonlist items will be different.

i've tried to bind the readiobuttonlist in code behind but the code behind
doesn't "know" the rbAnswer radiobutton that is in the gridview Item

Hope someone can help

8 Years
Discussion Span
Last Post by jvcoach23

Well, thanks to some help from Peter Vogel... here was the solution.
to add the radiobutton info on the page_PreRender event. I also wanted to have the selected value be "checked", so i had to add it in here.

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If Page.IsPostBack = False Then
If Me.dgQuestion.Rows.Count > 0 Then

Dim oSurveyAnswers As List(Of SurveyAnswers) = Nothing
Dim oSurveyAnswerController As New SurveyAnswers_Controller
oSurveyAnswers = oSurveyAnswerController.CallerName() 'This is the iList collection

Dim rdl As RadioButtonList
Dim i As Integer
For i = 0 To Me.dgQuestion.Rows.Count - 1 Step i + 1
rdl = CType(Me.dgQuestion.Rows(i).Cells(2).FindControl("rbAnswers"), RadioButtonList)
rdl.DataSource = oSurveyAnswerKeys
rdl.DataTextField = "RadioButtonText"
rdl.DataValueField = "ValueSavedToDb"
rdl.SelectedValue = oSurveyAnswers.Item(i).Answer.ToString
End If
End If
End Sub

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.