2015-10-21 60 views
0

向頁面加載時使用RadioButtonList()類創建的一組單選按鈕添加了一個事件,但嘗試設置控件的事件OnSelectedIndexChanged,但Visual Studio和頁面測試都給了我以下內容錯誤:嘗試以編程方式設置RadioButtonList的事件

System.Web.UI.WebControls.ListControl.Protected Overridable Sub OnSelectedIndexChanged(e As System.EventArgs) is not accessible in this context because it is '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 

回答

0

我想你想訂閱SelectedIndexChanged事件:

AddHandler group_answers.SelectedIndexChanged, AddressOf check_selection

+0

它工作正常!非常感謝你 – CesarDev

相關問題