RadioButton1触发事件

taylermail 2011-04-07 04:52:48
<asp:RadioButton id=RadioButton1 runat="server" GroupName="Sl">
</asp:RadioButton
当RadioButton1选中时触发事件怎么写
...全文
147 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxing2006 2011-04-07
  • 打赏
  • 举报
回复
属性 AutoPostBack = true
CheckOnchange事件
耗子哭死猫 2011-04-07
  • 打赏
  • 举报
回复
微软官方示例代码

/************************************* Module Header **************************************\
* Module Name: MainForm.cs
* Project: CSWinFormGroupRadioButtons
* Copyright (c) Microsoft Corporation.
*
* This sample demonstrates how to group the RadioButtons in the different containers.
*
* For more information about the RadioButton control, see:
*
* Windows Forms RadioButton control
* http://msdn.microsoft.com/en-us/library/f5h102xz.aspx
*
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\******************************************************************************************/

using System;
using System.Windows.Forms;

namespace CSWinFormGroupRadioButtons
{
public partial class MainForm : Form
{
// store the old RadioButton
//第一步创建一个RadioButton控件的对象
private RadioButton radTmp = null;

public MainForm()
{
InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
// we checked the rad1 in the MainForm.Designer.cs file
// then this RadioButton would be the old one
//第二步在初始加载的时候rad1为选中状态
radTmp = this.rad1;
}

// let the 4 Radiobuttons use this method to deal with their CheckedChanged event
// in the MainForm.Designer.cs file

//每当更改属性值的时候触发事件
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
// uncheck the old one
//第三步当点击其他RadioButton更改了属性值状态的时候,其他RadioButton控件为未选中,在根据参数选中状态,Lable控件显示的是当前控件选中的Name;
radTmp.Checked = false;
radTmp = (RadioButton)sender;

// find out the checked one
//这个是处理相同的业务
if (radTmp.Checked)
{
this.lb.Text = radTmp.Name + " 当前被选中的控件";
}
//这个是单独处理业务
if (rad1.Checked)
{
//rad1被选中处理业务
}
else if (rad2.Checked)
{
//rad2被选中处理业务
}
}

}
}

耗子哭死猫 2011-04-07
  • 打赏
  • 举报
回复

//每当更改属性值的时候触发事件
private void radioButton_CheckedChanged(object sender, EventArgs e)
taylermail 2011-04-07
  • 打赏
  • 举报
回复
如何写?
if (this.RadioButton1.Checked == true) { this.RadioButton1.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='A'"); }
if (this.RadioButton2.Checked == true) { this.RadioButton2.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='B'"); }
if (this.RadioButton3.Checked == true) { this.RadioButton3.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='C'"); }
if (this.RadioButton4.Checked == true) { this.RadioButton4.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='D'"); }
兔子-顾问 2011-04-07
  • 打赏
  • 举报
回复
写 OnClick

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧