Display selectedvalues of listbox as label - multiple values

后端 未结 1 1973
[愿得一人]
[愿得一人] 2021-01-28 11:30

I have got a list box called lstPTLNameDHOD which has multiple PTL names which gets selected using Ctrl. I want to display the selected names in a label or some way that the pe

相关标签:
1条回答
  • 2021-01-28 12:14

    You are only getting one name to display because your current code would always display name of the last item that is selected.

    I don't have a visual studio handy but you could try this:

    StringBuilder sbText = new StringBuilder();
    // Items collection
    foreach (ListItem item in lstPTLNameDHOD.Items)
    {
       if (item.Selected)
       {
           lbl1stPTL.Text = sbText.Append(item.Value.ToString()).ToString();
       }
    }
    

    You can probably refine this by adding a space or a comma between two item names but I hope you get the idea and it helps!

    Again, sorry for not having VS handy!

    0 讨论(0)
提交回复
热议问题