Basically I need to populate a listBox’s .Text value with a string and its .Value value with an int.
By doing this:
lbUsers.DataSource = new UserManagerBO().GetGlobalUserList();
lbUsers.DataBind();
This assigns a string to both .Value and .Text.
Now I know GetGlobalUserList() returns a string[] which is why I’m getting the behaviour above, so how to go about returning the int values along with the string ones? Maybe go 2D array? And then how to bind those results to the listbox?
Option 1
Let that method return
string[]and for value pickSelectedIndex.Option 2
Create a custom class as Damith answers.
Option 3
A
Dictionary<int, string>will suffice.Dictionary KeysforListBox ValueandDictionary ValuesforListBox Text.Say this is the dictionary returned by your method
Step 2:
Now it’s time to bind a Dictionary pair with your listbox. The following code binds to listbox.