从后面的 vb 代码设置单选按钮列表

Set radio button list from vb code behind

我有一个单选按钮列表。加载页面时,我有一些脚本和其他东西 运行 确定 ID 是否通过或未通过测试。所以我实际上想做的是当该页面加载时将我的单选按钮设置为在脚本运行后失败

列表如下:

<asp:radiobuttonlist id="rblInspectionStatus" CssClass="descbold"  runat="server" repeatColumns="2" repeatDirection="Horizontal">
       <asp:listitem Value="Pass">Pass</asp:listitem>
       <asp:listitem Value="Fail">Fail</asp:listitem>
</asp:radiobuttonlist>

我试过的是:

rblInspectionStatus.Items.FindByValue("Fail").Selected = True 
rblInspectionStatus.Items.FindByText("Fail").Selected = True
rblInspectionStatus.SelectedIndex |SelectedItem | SelectedValue

我不知道你想做什么 Sub 或者用户 Tony Hinkle 和用户 NoAlias 试图说的是正确的,但这是我的假设:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            cn.Open() 'Opens the connection
            cmd = New SqlCommand("SELECT PF FROM TABLE WHERE ID = '" & Session("ID") & "'", cn)
            drr = cmd.ExecuteReader
            If drr.Read Then
                rblInspectionStatus.ClearSelection()
                rblInspectionStatus.Items.FindByValue(drr.Items("PF")).Selected = True
            'FIELD PF data either Pass or Fail
            ElseIf Not drr.Read Then
                rblInspectionStatus.ClearSelection()
                rblInspectionStatus.SelectedIndex = -1
            End If
            cn.Close() 'Close the connection
        End Sub