我有一个单选按钮列表。加载页面时,我会运行一些脚本和其他内容来确定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
答案 0 :(得分:0)
我不知道你在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