Lucas
Lucas

Reputation: 125

ListBox gets wrong selected value, how can i get the correct value?

I have a listbox that has the following items and values right now.

Items, Misc. Charge/Taxes/Labor Charges

Value, 50.00/50.00/100.00

The problem is when i select the taxes item, it will turn it into Misc. Charges because they have the same value. Is it possible to have the listbox get the correct item and value if the values are the same??

Thank you!

Upvotes: 0

Views: 305

Answers (1)

Ross Barbish
Ross Barbish

Reputation: 679

Use the value attribute as the unique id (miscCharge, Taxes) and the text attribute as what is displayed to the user (50.00, 50.00).

<asp:ListItem value="item1" Text="50" Selected="True"></asp:ListItem>
<asp:ListItem value="item2" Text="50"></asp:ListItem>

ListItem selectedItem = list1.SelectedItem;
string id = list1.SelectedItem.Value;
string text = list1.SelectedItem.Text;

Upvotes: 1

Related Questions