Make ListBox items have a different value than item text

前端 未结 5 1609
旧时难觅i
旧时难觅i 2020-12-08 21:18

I want a ListBox full of items. Although, each item should have a different value. So when the user selects an item and presses a button, a method will be calle

5条回答
  •  无人及你
    2020-12-08 22:03

    Very simple:

    foreach(var item in *Your Source List*)
            {
                ListItem dataItem =  new ListItem();
                dataItem.Text = "value to show";
                dataItem.Value = *another value you want*;
                listBox.Items.Add(dataItem);
            }
    

提交回复
热议问题