【问题标题】:How to make radiobutton selected one at time?如何使单选按钮一次选择一个?
【发布时间】:2014-05-15 16:56:26
【问题描述】:

我有下面的代码在gridview中显示信息并允许用户选择选项,但我希望用户只选择一个选项而不是多个选项。

 <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="ID">
<Columns>
   <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
   <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
   <asp:TemplateField HeaderText="Select">
       <ItemTemplate>
           <asp:RadioButton ID="CheckBox1" runat="server" GroupName="select"/>
       </ItemTemplate>
   </asp:TemplateField>
</Columns>

那么我怎样才能让用户只选中一个 RadioButton?

【问题讨论】:

  • 您的意思是在所有行中只能选择一个单选按钮(而不是在每一行中)?
  • 是的,我就是这个意思

标签: c# asp.net templates gridview


【解决方案1】:

使用 RadioButtonList

 <asp:RadioButtonList id="Rdlist" runat="server">
            <asp:ListItem>One</asp:ListItem>
            <asp:ListItem>Two</asp:ListItem>
            <asp:ListItem>Three</asp:ListItem>
         </asp:RadioButtonList>

该控件在http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist(v=vs.110).aspx上有详细记录

【讨论】:

    【解决方案2】:

    使用简单的输入类型 = 收音机,并确保所有收音机的名称应该相同,您只希望选择一个

    <input type="radio" ID="CheckBox1" runat="server"  name="somename" />
    

    【讨论】:

      【解决方案3】:

      只需将 GroupName 添加到网格中的每个单选按钮即可。

      见定义->http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton.groupname(v=vs.110).aspx

      【讨论】:

        猜你喜欢
        • 2016-01-09
        • 2012-04-23
        • 1970-01-01
        • 1970-01-01
        • 2017-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-24
        相关资源
        最近更新 更多