试图以编程方式设置RadioButtonList的事件
本文关键字:RadioButtonList 事件 设置 方式 编程 | 更新日期: 2023-09-27 18:18:43
在页面加载时使用RadioButtonList()
类创建了一组单选按钮,在尝试设置控件的事件OnSelectedIndexChanged
时,但是Visual Studio和页面测试都给了我以下错误:
System.Web.UI.WebControls.ListControl。受保护的可重写潜艇OnSelectedIndexChanged(如System.EventArgs)在因为它是"Protected"。
为什么不能以编程方式访问此控件的此事件并告诉我它是Protected
?
这是代码:
Sub Page_Load(Sender As Object, E As EventArgs)
Dim group_answers As New RadioButtonList()
group_answers.AutoPostBack = True
AddHandler group_answers.OnSelectedIndexChanged, AddressOf check_selection
group_answers.Items.Add(New ListItem("0%", "17"))
group_answers.Items.Add(New ListItem("10%", "18"))
group_answers.Items.Add(New ListItem("20%", "19"))
group_answers.Items.Add(New ListItem("30%", "20"))
group_answers.RepeatDirection = RepeatDirection.Horizontal
question_answer.Controls.Add(group_answers)
End Sub
我想你想订阅SelectedIndexChanged
事件:
AddHandler group_answers.SelectedIndexChanged, AddressOf check_selection