GridView 中的 RadioButton 列表 - 可以进行 2 种方式的数据绑定吗?
如果我在 GridView 的 TemplateField 中有一个 ASP.Net RadioButtonList,它与数据控件绑定,我可以在页面加载时进行数据绑定,如下所示:
<asp:RadioButtonList SelectedValue='<%#Eval("RequirementOption")%>'>
因此,当 gridview 呈现时,用户可以为中的每一行选择一个选项网格。
我想知道的是,当按下保存按钮并发生回发时,是否有一种方法可以自动将这些选定的值推回数据控件,以便可以保存它们,或者我是否必须手动循环所有网格行并提取所选值,如下所示:
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
可以通过数据绑定自动完成吗?
注意:我说的是更新所有行,然后通过回发访问所有行,而不是通过内联编辑一次访问一行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,只要您指定 Bind 而不是 Eval,selectedValue 就可用。
(假设您以通常的方式更新记录)
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)