选项 1
让该方法返回string[] 并为值选择SelectedIndex。
选项 2
创建一个自定义类作为 Damith 的答案。
选项 3
Dictionary<int, string> 就足够了。
Dictionary Keys 为ListBox Value 和Dictionary Values 为ListBox Text。
说这是你的方法返回的字典
//Adding key value pair to the dictionary
Dictionary<int, string> dStudent = new Dictionary<int, string>();
dStudent.Add(0, "Eena");
dStudent.Add(1, "Meena");
dStudent.Add(2, "Deeka");
dStudent.Add(3, "Tom");
dStudent.Add(4, "Dick");
dStudent.Add(5, "Harry");
dStudent.Add(6, "Yamla");
dStudent.Add(7, "Pagla");
dStudent.Add(8, "Dewana");
dStudent.Add(9, "Guru");
dStudent.Add(10, "Sholay");
第 2 步:
现在是时候将字典对与您的列表框绑定了。以下代码绑定到列表框。
//binding to the list
lst.DataTextField = "Value";
lst.DataValueField = "Key";
lst.DataSource = dStudent;
lst.DataBind();