Link to home
Start Free TrialLog in
Avatar of lenmor
lenmor

asked on

Compiler Error Message: CS0122

Hi, I am trying to add a eventhandler to a dropdown, getting this error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0122: 'System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(System.EventArgs)' is inaccessible due to its protection level

Source Error:

 

Line 66:     dropProject.ID = "DropDown_Project";
Line 67:     dropProject.AutoPostBack = true;
Line 68:     dropProject.OnSelectedIndexChanged += new EventHandler(this.dropProject_Click);

 
Avatar of Harshad09
Harshad09

Try changing the access modifier of OnSelectedIndexChanged method to public
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lenmor

ASKER

sweet:) thanks
I am using a dynamically created control; putting in SelectedIndexChanged works for the compiler but it doesn't trigger the event; Any ideas why not?

 foreach ( Control c in PlaceHolder1.Controls)
            {
                (c as System.Web.UI.WebControls.DropDownList).Items.Add(new ListItem(""));
                (c as System.Web.UI.WebControls.DropDownList).Items.Add(new ListItem("First"));
                (c as System.Web.UI.WebControls.DropDownList).Items.Add(new ListItem("Second"));
                (c as System.Web.UI.WebControls.DropDownList).SelectedIndexChanged += new EventHandler(dd123_selectindexchanged);
            };