如何在 gridview 中找到 radiobuttonlist 及其项目?网格视图代码:
<asp:TemplateField HeaderStyle-Width="20px">
<ItemTemplate>
<asp:RadioButtonList ID="rbl_NIU" runat="server" RepeatDirection="Horizontal" BorderStyle="None" BorderWidth="0px" BorderColor="Transparent">
<asp:ListItem Text="N" Value="1" ></asp:ListItem>
<asp:ListItem Text="I" Value="2" ></asp:ListItem>
<asp:ListItem Text="U" Value="3" ></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
和 .vb 代码:
Protected Sub gvImport_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvImport.RowDataBound
'Dim radio As RadioButtonList = DirectCast(e.Row.FindControl("rbl_NIU"), RadioButtonList)
'Dim radio As RadioButtonList = TryCast(sender, RadioButtonList)
Dim radio As RadioButtonList = CType(e.Row.FindControl("rbl_NIU"), RadioButtonList)
For Each par As Paraugs In list
For Each item As RadioButton In radio.Items
par.Write.ToString()
Next
Next
End Sub
我已经尝试了一切,但每次我在“For Each item”中得到“对象引用未设置为对象的实例”并且在断点“radio”返回“Nothing”
问题出在哪里?请帮忙!谢谢!