views:

959

answers:

1

If I have an ASP.Net RadioButtonList within a TemplateField in a GridView, which is tied to a Data Control, I can get databinding on page loading like so:

<asp:RadioButtonList SelectedValue='<%#Eval("RequirementOption")%>'>

So when the gridview renders, the user can select an option for each row in the grid.

What I'm wondering is, when the save button is pressed and a postback occurs, is there a way to automatically push these selected values back through to the datacontrol so they can be saved, or do I have to manually loop through all the grid rows and exract the chosen value, like so:

For iRow As Integer = 0 To Me.myGrid.Rows.Count - 1
  Dim selectedValue As String = CType(Me.myGrid.Rows(iRow).FindControl("RequirementOption"), RadioButtonList).SelectedValue
  '...Load up the appropriate class and save the selected value  
  Next

Can it be done automatically via databinding?

NOTE: I am talking about about updating all the rows and then accessing all of them opn postback, not one row at a time via inline editing.

A: 

Yes, the selectedValue will be available as long as you specify Bind instead of Eval.

(assuming you're updating a record in the usual way)

ScottE
Where is it available, how do I access it? The gridView.DataSource is Nothing.
tbone
As far as I can tell, this answer is incorrect.
tbone
Did you add that comment about updating all at once after? That definitely changes things. Otherwise, an EditItemTemplate would have done the trick. Not sure why you voted down my answer, because your question was not complete.
ScottE