0

I have a listbox :

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem Value="genyn">MAS Meeting</asp:ListItem>   
<asp:ListItem Value="smartyn">Smart Meeting</asp:ListItem>  
<asp:ListItem Value="genyn">Project Meeting</asp:ListItem>
</asp:ListBox>

In the code behind:

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
 label1.Text= ListBox1.SelectedItem.Text;
}

when I select Project Meeting in the ListBox, label1 has the text "MAS Meeting". But i want it hav Project Meeting. Is it because I have same value for first and third listitem?

Can anyone help me? Thanks in advance

Shanna
  • 753
  • 4
  • 14
  • 34

2 Answers2

1

You have the same values for MAS Meeting and Project Meeting - that can cause your problem. Try setting different values for different list items to avoid confusion:

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
    <asp:ListItem Value="genyn">MAS Meeting</asp:ListItem>   
    <asp:ListItem Value="smartyn">Smart Meeting</asp:ListItem>  
    <asp:ListItem Value="another_genyn">Project Meeting</asp:ListItem>
</asp:ListBox>
Andrei
  • 55,890
  • 9
  • 87
  • 108
1

You could not do it such a way.

The value attribute should be unique, otherwise you will get the first matched item from the select, mean asp.net List

<asp:ListItem Value="diffValue">Project Meeting</asp:ListItem>
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120