我不知道这是否可能,但我试图设置 a asp:CheckBox
, in a FormView
, to Checked=True
if a value in a database = yes|no|pending etc
...
这是后面的代码(在 PreRender Sub 中):
Dim rowHiredStatus As DataRowView = CType(fvRecruitInterviewed.DataItem, DataRowView)
Dim lblTestHiredStatus As Label = CType(fvRecruitInterviewed.FindControl("lblTestHiredStatus"), Label)
Dim chkHiredPending As CheckBox = CType(fvRecruitInterviewed.FindControl("chkHiredPending"), CheckBox)
Dim chkHiredNo As CheckBox = CType(fvRecruitInterviewed.FindControl("chkHiredNo"), CheckBox)
Dim chkHiredYes As CheckBox = CType(fvRecruitInterviewed.FindControl("chkHiredYes"), CheckBox)
If Not IsNothing(rowHiredStatus) Then
Dim strHiredStatus As String
strHiredStatus = rowHiredStatus("HiredStatus").ToString()
lblTestHiredStatus.Text = strHiredStatus
If strHiredStatus = "yes" Then
chkHiredYes.Checked = True
lblTestHiredStatus.Text = strHiredStatus
ElseIf (strHiredStatus = "no") Then
chkHiredNo.Checked = True
lblTestHiredStatus.Text = strHiredStatus
Else
chkHiredPending.Checked = True
lblTestHiredStatus.Text = strHiredStatus
End If
End If
在设计视图中:
<asp:CheckBox ID="chkHiredPending" runat="server" Text="Pending" />
<br />
<asp:CheckBox ID="chkHiredNo" runat="server" Text="Not Hired"/>
<br />
<asp:CheckBox ID="chkHiredYes" runat="server" Text="Hired" />
<br />
<asp:Label ID="lblTestHiredStatus" runat="server" />
令人沮丧的是,测试标签显示正确的数据,但复选框不会改变。它只是默认为待处理的复选框。
使用一个RadioButton
组或者RadioButtonList
会很好,如果这更容易/可能的话