尝试以编程方式设置RadioButtonList的事件

时间:2015-10-21 11:42:51

标签: c# asp.net vb.net forms event-handling

在页面加载时使用RadioButtonList()类创建的一组单选按钮添加了一个事件,同时尝试设置控件的事件OnSelectedIndexChanged,但Visual Studio和页面测试都给了我以下错误:

  

System.Web.UI.WebControls.ListControl.Protected Overridable Sub   无法访问OnSelectedIndexChanged(e As System.EventArgs)   这个背景是因为它受到了保护'。

为什么无法以编程方式访问此控件的此事件并告诉我它是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

1 个答案:

答案 0 :(得分:0)

我认为您要订阅SelectedIndexChanged事件:

AddHandler group_answers.SelectedIndexChanged, AddressOf check_selection