如何选择一个radiobutton? [英] How to make radiobutton selected one at time?
问题描述
我有以下代码将信息显示在gridview中并允许用户选择,但我希望用户只选择一个选项而不是多个选项。
< pre lang =HTML> < asp:GridView ID = grid runat = server AutoGenerateColumns = False DataSourceID = SqlDataSource1 d ataKeyNames = ID >
< 列 >
< asp:BoundField DataField = ID HeaderText = ID SortExpression = ID / >
< asp:BoundField DataField = 标题 HeaderText = 标题 SortExpression = 标题 / >
< asp:TemplateField HeaderText = 选择 >
< ItemTemplate >
< asp:RadioButton ID = CheckBox1 runat = server < span class =code-attribute> GroupName = 选择 / >
< / ItemTemplate >
< < span class =code-leadattribute> / asp:TemplateField >
< /列 >
那么如何让用户只检查一个RadioButton?
我建议使用RadioButtonList控件而不是GridView, http://asp-net-example.blogspot.com/2008/10/radiobuttonlist-example-how-to-use.html [ ^ ]
网上有很多样品,但上面的链接很好。
I have the below code to display information into gridview and enable user to select choice, but I want user to select only one choice not multiple choices.
<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>
So how can I allow user to check only one RadioButton?
I would suggest using a RadioButtonList control instead of a GridView, http://asp-net-example.blogspot.com/2008/10/radiobuttonlist-example-how-to-use.html[^]
There are lots of samples online but the above link is a good one.
这篇关于如何选择一个radiobutton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!