Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox not displaying contents returned from method

Status
Not open for further replies.

mit99mh

Programmer
Sep 24, 2002
246
GB
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( &quot;<li>&quot; + li.Text );
}

private ListBox SetForwardOptions( int roleId )
{
ListBox listOptions = new ListBox();
switch( roleId )
{
//spoc
case 1:
listOptions.Items.Add( new ListItem( &quot;SPOC&quot;, &quot;1&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Theme Owner&quot;, &quot;4&quot; ) );
listOptions.Items.Add( new ListItem( &quot;IMT&quot;, &quot;7&quot; ) );
break;
//gatekeeper
case 2:
listOptions.Items.Add( new ListItem( &quot;SPOC&quot;, &quot;1&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Theme Owner&quot;, &quot;4&quot; ) );
break;
//topic owner
case 3:
listOptions.Items.Add( new ListItem( &quot;SPOC&quot;, &quot;1&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Theme Owner&quot;, &quot;4&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Topic Owner&quot;, &quot;3&quot; ) );
listOptions.Items.Add( new ListItem( &quot;IMT&quot;, &quot;7&quot; ) );
break;
//theme owner
case 4:
listOptions.Items.Add( new ListItem( &quot;SPOC&quot;, &quot;1&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Theme Owner&quot;, &quot;4&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Topic Owner&quot;, &quot;3&quot; ) );
listOptions.Items.Add( new ListItem( &quot;IMT&quot;, &quot;7&quot; ) );
break;
//imt
case 7:
listOptions.Items.Add( new ListItem( &quot;SPOC&quot;, &quot;1&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Theme Owner&quot;, &quot;4&quot; ) );
listOptions.Items.Add( new ListItem( &quot;Topic Owner&quot;, &quot;3&quot; ) );
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);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top