1

如何在 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”

问题出在哪里?请帮忙!谢谢!

4

1 回答 1

0

当你运行gvImport.RowDataBoundthis 时,它仍然会计算标题,所以你需要在 Sub 的顶部有一个快速的 if 语句:

If e.Row.RowType = DataControlRowType.DataRow Then
'Look for radio button list in this
End If
于 2013-09-23T09:12:23.560 回答