| | |
DataBound radiobuttonlist in a gridview cell
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: How to store sent mails
- Next Thread: ASP.NET 2.0 and Exchange 2007
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form forms grid gridview gudi homeedition hosting iis image javascript jquery list menu mssql multistepregistration nameisnotdeclared novell objects opera order problem ratings redirect registration relationaldatabases rotatepage search security select serializesmo.table sessionvariables silverlight smoobjects sql ssl tracking treeview typeof validatedate validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment wizard xml xsl





