【问题标题】:About RadioButton CheckedChanged event关于 RadioButton CheckedChanged 事件
【发布时间】:2010-10-03 14:59:52
【问题描述】:

您好,我使用单个文本框来查询不同类型的选择,例如,当我选择第一个 RadioButton(姓氏)时,我按客户姓氏搜索,当我选择第二个 RadioButton(文档代码)时,我按代码搜索等等,请问我该如何管理或处理异常,例如,如果用户选择“按日期搜索”并发送字符串类型?

我正在使用 C# 3.5 - Asp.net

我想用正则表达式来做它并在 RadioButton 事件中添加它,所以当用户更改收音机时,他可以在 optionA 中输入一些字符,在 Option B 中输入更多字符,在 OptionC 中输入日期......(正则表达式)

提前致谢

【问题讨论】:

标签: c# asp.net radio-button


【解决方案1】:

如果您使用的是 ASP Web 控件单选按钮列表,那么您可以在它们是回发时进行大量更改。您可以将属性设置为 SelectIndexChanged,因此无论何时更改它们都会导致回发,然后您可以从它们(验证)中执行任何操作。 例如:

   <asp:radioButtonList
     id="radio1" runat="server" 
     autoPostBack="true"
     cellSpacing="20"
     repeatColumns="3"
     repeatDirection="horizontal"
     RepeatLayout="table"
     textAlign="right"
     OnSelectedIndexChanged="radio_SelectedIndexChanged">
     <asp:ListItem text="10pt" value="itsMe"/>  
     <asp:ListItem text="14pt" value="itsYou"/>  
     <asp:ListItem text="16pt" value="Neither"/>  
  </asp:radioButtonList>

在您应该拥有的服务器上

protected void radio_SelectedIndexChanged(object sender, EventArgs e)
{
 //do whatever you want by calling the name of the radio id
 //example

  if(radio1.SelectedItem.Value=="(whatever you want to test)"

}

【讨论】:

    猜你喜欢
    • 2019-09-28
    • 2015-11-22
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 2015-11-04
    相关资源
    最近更新 更多