[英]How can I use radiobuttonlist selectedvalue in autopostback event?
html File: html文件:
<p>Delivery Type :</p>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Value="0">Electronic</asp:ListItem>
<asp:ListItem Value="1">Paper Mail</asp:ListItem>
</asp:RadioButtonList>
Code-behind page: 后台代码页:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(RadioButtonList1.SelectedItem.Value = )
{
}
}
I want to use radiobutton so that if user selects the electronic mail option, the Email field should be displayed. 我想使用单选按钮,以便如果用户选择电子邮件选项,则应显示“电子邮件”字段。 So as per my knowledge I am trying if radiobuttonlist selected value is 0 then email field should be displayed.
因此,据我所知,我正在尝试如果单选按钮列表的选定值为0,则应显示电子邮件字段。 But I am getting an error in the
if
condition itself: 但是我在
if
条件本身中遇到了一个错误:
cannot convert type string to bool
无法将类型字符串转换为bool
When using several Radiobuttons (instead of Radio Button List) and manually setting them to the same group: 使用多个单选按钮(而不是单选按钮列表)并将其手动设置为同一组时:
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="RadioButtonList" />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="RadioButtonList" />
The following should work, 以下应该工作,
if(RadioButton1.Checked)
{
}
This way there should be no datatype conversions necessary, avoiding the errors you seem to be getting. 这样,就无需进行数据类型转换,避免了您似乎遇到的错误。 Hope this works.
希望这行得通。
try 尝试
if(RadioButtonList1.SelectedItem.Value == "0"){
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.