.

LoadControl – dynamically load controls

loading a control dynamically 

steps:

1- declare a control
2- initiate control using loadcontrol statement
3- add control to a parent control

see important and related bits in bold :


 

private void PopulatePage()
{
        CustomProcesses CPs = new CustomProcesses();

        foreach (CustomProcess CP in CPs)
        {
                Custom_UI_CustomProcessRow PRow =
null;
                PRow = (Custom_UI_CustomProcessRow)LoadControl(@"Custom UI\CustomProcessRow.ascx"
);
                PRow.CustomProcess = CP;
               
PlaceHolder1.Controls.Add(PRow);
        }

        Custom_UI_CustomProcessRow NewPRow = null;
        NewPRow = (Custom_UI_CustomProcessRow)LoadControl( @"Custom UI\CustomProcessRow.ascx"); 
        NewPRow.CustomProcess = null;

        PlaceHolder1.Controls.Add(NewPRow);

}

What's your thoughts on this?

*

Protected by WP Anti Spam