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 .ListContr ol.OnSelec tedIndexCh anged(Syst em.EventAr gs)' is inaccessible due to its protection level
Source Error:
Line 66: dropProject.ID = "DropDown_Project";
Line 67: dropProject.AutoPostBack = true;
Line 68: dropProject.OnSelectedInde xChanged += new EventHandler(this.dropProj ect_Click) ;
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
Source Error:
Line 66: dropProject.ID = "DropDown_Project";
Line 67: dropProject.AutoPostBack = true;
Line 68: dropProject.OnSelectedInde
Try changing the access modifier of OnSelectedIndexChanged method to public
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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. DropDownLi st).Items. Add(new ListItem(""));
(c as System.Web.UI.WebControls. DropDownLi st).Items. Add(new ListItem("First"));
(c as System.Web.UI.WebControls. DropDownLi st).Items. Add(new ListItem("Second"));
(c as System.Web.UI.WebControls. DropDownLi st).Select edIndexCha nged += new EventHandler(dd123_selecti ndexchange d);
};
foreach ( Control c in PlaceHolder1.Controls)
{
(c as System.Web.UI.WebControls.
(c as System.Web.UI.WebControls.
(c as System.Web.UI.WebControls.
(c as System.Web.UI.WebControls.
};