オプション 1
そのメソッドが返さstring[]
れ、値が pick になるようにしますSelectedIndex
。
オプション 2
ダミスの回答としてカスタム クラスを作成します。
オプション 3
ADictionary<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();