DataBound radiobuttonlist in a gridview cell

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2007
Posts: 4
Reputation: jvcoach23 is an unknown quantity at this point 
Solved Threads: 0
jvcoach23 jvcoach23 is offline Offline
Newbie Poster

DataBound radiobuttonlist in a gridview cell

 
0
  #1
Oct 17th, 2008
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
anymore.

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

Hope someone can help
Shannon
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 4
Reputation: jvcoach23 is an unknown quantity at this point 
Solved Threads: 0
jvcoach23 jvcoach23 is offline Offline
Newbie Poster

Re: DataBound radiobuttonlist in a gridview cell

 
0
  #2
Oct 21st, 2008
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
rdl.DataBind()
Next
End If
End If
End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC