在 ASPX 中从 JS 中删除单选按钮选定值后.cs所选值将保持不变
本文关键字:cs 中从 ASPX JS 单选按钮 删除 | 更新日期: 2023-09-27 18:32:09
我有一个asp单选按钮列表控件,如下所示:
<asp:RadioButtonList ID="radio2" runat="server" EnableViewState="false">
<asp:ListItem Text="YES" Value="0"></asp:ListItem>
<asp:ListItem Text="NO" Value="1" Selected="True"></asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="btnsubmit" runat="server" Text="submit" OnClick="btnsubmit_Click" />
当页面在浏览器上加载时,我选择是选项无线电。然后从控制台中删除它的检查属性,如下所示:
$("#radio2 input[type='radio']").prop("checked",false);
现在,如果我尝试在单击按钮提交时访问单选按钮列表,如下所示
protected void btnsubmit_Click(object sender, EventArgs e)
{
foreach (ListItem itemRow in radio2.Items)
{
if (itemRow.Selected)
{ }
}
}
在这里,对于是的项目行,我选择的值为真,而它应该是假的。
有什么要求?
请正确解释。
itemrow 您获得的选定值为 true 因为,只有页面加载时间清除脚本中选中的属性。但是在设计中你写了
"<asp:ListItem Text="NO" Value="1" Selected="True"></asp:ListItem>
"
这就是为什么它采用单选按钮列表的默认值。删除 thet Selected="True",这样它就不会采用任何默认值。