我有一个页面,我正在检查几组单选按钮的值。对于每个组,如果选择了单选按钮,这是我需要保存以稍后存储在我的数据库中的属性。正如现在的代码所示,单选按钮 Checked 属性被正确设置为“true”,但是,当我从页面读回它时,它返回为“false”,即使我可以看到它实际上已被选中屏幕。
以下是代码块:
标记:
<form action="#">
<div class="card-content center-align">
<div class="row">
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoArabic1" runat="server" GroupName="ethnicity" />
<label>Arabic, Middle Easterner</label>
</div>
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoAsian1" runat="server" GroupName="ethnicity" />
<label>Asian, Pacific Islander, Indian</label>
</div>
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoBlack1" runat="server" GroupName="ethnicity" />
<label>African American or Black</label>
</div>
</div>
</div>
<div class="card-content center-align">
<div class="row">
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoWhite1" runat="server" GroupName="ethnicity" />
<label>White, Anglo, European American</label>
</div>
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoHispanic1" runat="server" GroupName="ethnicity" />
<label>Hispanic, Latino</label>
</div>
<div class="col s4 m4 l4">
<asp:RadioButton CssClass="with-gap" ID="rdoOther1" runat="server" GroupName="ethnicity" />
<label>Other</label>
</div>
</div>
</div>
</form>
VB代码:
If rdoArabic1.Checked = True Then
ethnicity = "1"
ElseIf rdoAsian1.Checked = True Then
ethnicity = "2"
ElseIf rdoBlack1.Checked = True Then
ethnicity = "3"
ElseIf rdoWhite1.Checked = True Then
ethnicity = "4"
ElseIf rdoHispanic1.Checked = True Then
ethnicity = "5"
ElseIf rdoOther1.Checked = True Then
ethnicity = "6"
End If
无论如何,我已经把头撞在这堵墙上一段时间了,我似乎看不出我错过了什么导致它重置。我已经单步执行了代码,当页面加载并处理来自数据库的信息时,Checked 属性被设置为 True,只是由于某种原因没有正确地从表单中读取它。