使用 RadioButton GroupName 时出现问题

问题描述 投票:0回答:1

我有一个问题 - 我有多个具有相同组名称的单选按钮。

我有带有后端代码的按钮,例如

degg26.Checked = True
; 当我单击按钮时,它应该检查
degg26
值。

假设我在

degg26
之前手动检查了任何单选按钮,然后单击该按钮,代码正常运行并且
degg26
被选中。

如果我在

degg26
之后手动选中任何单选按钮,然后单击该按钮,则没有任何效果,并且
degg26
未选中

有什么帮助吗?!

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="tecTaqeem2.aspx.vb" Inherits="tecTaqeem2" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <br />
            <br />
            <table>
                <tr>
            <td>
            <asp:RadioButton ID="degg20" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="0" />
            </td>
            <td>
            <asp:RadioButton ID="degg23" CssClass="ChkBoxClassTxt" runat="server"  
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="3" />
            </td>
            <td>
            <asp:RadioButton ID="degg24" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="4" />
            </td>
            <td>
            <asp:RadioButton ID="degg25" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="5" />
            </td>
            <td>
            <asp:RadioButton ID="degg26" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="6" />
            </td>
            <td>
            <asp:RadioButton ID="degg27" CssClass="ChkBoxClassTxt" runat="server"  
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="7" />
            </td>
            <td>
            <asp:RadioButton ID="degg28" CssClass="ChkBoxClassTxt" runat="server"  
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="8" />
            </td>
            <td>
            <asp:RadioButton ID="degg29" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="9" />
            </td>
            <td>
            <asp:RadioButton ID="degg210" CssClass="ChkBoxClassTxt" runat="server"   
            style="font-size:20px; color:black; margin:0px; height: 10px; width:10px; accent-color:red;" GroupName="G2" Text="10" />
            </td>
            </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
asp.net
1个回答
0
投票

在 Asp.Net 中,组没有超过一项选中项的限制。使用单选按钮时这可能是一个问题。请使用

RadioButtonList
来代替。

发生的事情是,当您单击一个选项,然后单击另一个选项时,两个单选按钮在应用程序后面的代码中都是 true。这可以在 Visual Studio 的调试模式下看到。生成的 html 页面有两个

input
选项标记已选中(检查您的 html 源页面)。由于它们具有相同的名称,浏览器将第一个显示为选中状态,并忽略其他任何一个。

© www.soinside.com 2019 - 2024. All rights reserved.