小编WIS*_*MAN的帖子

在动态表中的RadioButton CheckedChanges中添加新的eventHandler

我想另一个添加eventHandlerRadioButton.这是示例代码(正在运行):

ASP.NET:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" />
Run Code Online (Sandbox Code Playgroud)

C#:

protected void Page_Load(object sender, EventArgs e)
{
    RadioButton RB1 = new RadioButton();
    RB1.ID = "1";
    RB1.GroupName = "bla";
    RB1.CheckedChanged += new EventHandler(CheckedChanged);
    RadioButton RB2 = new RadioButton();
    RB2.ID = "2";
    RB2.GroupName = "bla";
    RB2.CheckedChanged += new EventHandler(CheckedChanged);
    PlaceHolder1.Controls.Add(RB1);
    PlaceHolder1.Controls.Add(RB2);

}
protected void CheckedChanged(object sender, EventArgs e)
{
    Label1.Text = ((RadioButton)sender).ID;
}
Run Code Online (Sandbox Code Playgroud)

在我的项目中,我有动态创建RadioButtons(从数据库中获取的行数).相同的添加eventHandler不起作用,但如果我写

MyRadioButton.Load += new EventHandler(Another_method);
Run Code Online (Sandbox Code Playgroud)

在 …

c# asp.net event-handling radio-button

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

c# ×1

event-handling ×1

radio-button ×1