Brian
Brian

Reputation: 163

Can't get value from listbox

Bean Class

 public partial class IPSFlightPath {            
        private string nameField;            
        private string sidField;            
        private int selectedField;}

Main Class

1.1.Set value for listbox

IPSFlightPath[] arrFlightPath = ipsChannel.paths;                           
foreach (IPSFlightPath flightPath in arrFlightPath)
{
  if (flightPath.selected != 0)
  {
  lbSelected.Items.Add(flightPath.name);
  }
}

1.2.Get value from listbox

string FP = lbSelected.SelectedItem.Value.ToString();

It just set FP is name , didn't get selectedValue of object. Example: row1 show nameField is 'FlightPath1' which contain sidField is '1'.

Thanks for your help.

Upvotes: 0

Views: 231

Answers (1)

cuongle
cuongle

Reputation: 75296

Should be:

lbSelected.Items.Add(new ListItem(flightPath.name, flightPath.sidField));

Upvotes: 1

Related Questions