简体   繁体   中英

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:

<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 .

<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

SelectedIndex:Gets or sets the lowest ordinal index of the selected items in the list.

RadioButtonList1.SelectedIndex

SelectedItem:Gets the selected item with the lowest index in the list control.

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.

RadioButtonList1.SelectedValue  

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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