简体   繁体   English

如何从单选按钮列表中选择单选按钮

[英]how to get selected radiobutton from radiobuttonlist

i have one radiobuttonlist which consists of two radio button,following price discount,another is percent discount. 我有一个单选按钮列表,其中包括两个单选按钮,下面是价格折扣,另一个是百分比折扣。 the code snippet of aspx file as follows: aspx文件的代码段如下:

<td class="style8">
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
                    <asp:ListItem Value="1">Price Discount</asp:ListItem>
                    <asp:ListItem Value="2">Percent Discount</asp:ListItem>
                </asp:RadioButtonList>
</td>

Try to do this 尝试做这个

RadioButtonList1.SelectedValue

return an integer number (1 or 2) which you have declared in your aspx code if select price discount then returns 1 of select percent then return 2 . 如果选择价格折扣,则返回您在aspx代码中声明的整数(1或2),然后返回选择百分比的1,然后返回2。

<asp:ListItem Value="1">Price Discount</asp:ListItem>
 <asp:ListItem Value="2">Percent Discount</asp:ListItem>

You can achieve this in two way. 您可以通过两种方式来实现。

1. If you want to select radio button by your value then you can write


    RadioButtonList1.SelectedValue 

2.If you want to select radio button by your Item then you can write

RadioButtonList1.SelectedItem

We can get RadioButtonList SelectedIndex,SelectedItem and SelectedValue 我们可以得到RadioButtonList SelectedIndex,SelectedItem和SelectedValue

SelectedIndex:Gets or sets the lowest ordinal index of the selected items in the list. SelectedIndex:获取或设置列表中所选项目的最低序号。

RadioButtonList1.SelectedIndex

SelectedItem:Gets the selected item with the lowest index in the list control. SelectedItem:获取列表控件中索引最低的所选项目。

RadioButtonList1.SelectedItem 

SelectedValue:Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value. SelectedValue:获取列表控件中所选项目的值,或选择列表控件中包含指定值的项目。

RadioButtonList1.SelectedValue  

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist%28v=vs.110%29.aspx http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.radiobuttonlist%28v=vs.110%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM