The method below returns a ListBox, it works as I can iterate through the items and the correct items are returned.
However the web control is not populated. Any help much appreciated.
//declaration
protected System.Web.UI.WebControls.ListBox forwardOptions;
//assign listbox to return from method
forwardOption = SetForwardOptions(currentRoleId);
foreach(ListItem li in forwardOptions.Items)
{
Response.Write( "<li>" + li.Text );
}
private ListBox SetForwardOptions( int roleId )
{
ListBox listOptions = new ListBox();
switch( roleId )
{
//spoc
case 1:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//gatekeeper
case 2:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
break;
//topic owner
case 3:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//theme owner
case 4:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//imt
case 7:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
break;
//what to do here?
//default:
}
//set number of rows to number of items
listOptions.Rows = listOptions.Items.Count;
Response.Write( listOptions.Rows.ToString() );
return(listOptions);
}
However the web control is not populated. Any help much appreciated.
//declaration
protected System.Web.UI.WebControls.ListBox forwardOptions;
//assign listbox to return from method
forwardOption = SetForwardOptions(currentRoleId);
foreach(ListItem li in forwardOptions.Items)
{
Response.Write( "<li>" + li.Text );
}
private ListBox SetForwardOptions( int roleId )
{
ListBox listOptions = new ListBox();
switch( roleId )
{
//spoc
case 1:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//gatekeeper
case 2:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
break;
//topic owner
case 3:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//theme owner
case 4:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
listOptions.Items.Add( new ListItem( "IMT", "7" ) );
break;
//imt
case 7:
listOptions.Items.Add( new ListItem( "SPOC", "1" ) );
listOptions.Items.Add( new ListItem( "Theme Owner", "4" ) );
listOptions.Items.Add( new ListItem( "Topic Owner", "3" ) );
break;
//what to do here?
//default:
}
//set number of rows to number of items
listOptions.Rows = listOptions.Items.Count;
Response.Write( listOptions.Rows.ToString() );
return(listOptions);
}