I have a list box which is populated by this code:
- lstOutcome.Items.Add(lstMap.SelectedItem.Text);
In the listbox lstOutcome, I need to be able to loop through the listbox and be able to take the value of the first,second, etc, list items.
The reason I need to loop through each line and grab the value of that line is so I can use whatever value was in that line for populating something else.
For example, in my list box I have:
- 1
- 2
- 3
I need to be able to loop through the listbox on button click and have the values assigned to txtboxes:
- textbox1.Text = 'item 1 in the listbox';
- textbox2.Text = 'item 2 in the listbox';
- textbox3.Text = 'item 3 in the listbox';
I am not sure if I need an array or how this can be accomplished. The point of this example is that I will actually be using the items in the listbox to map columns. I am importing an Microsoft Excel spreadsheet. In lstMap I have the column names and I am trying to get the column names to match my database. Using this code I am trying to take the values of the listbox:
foreach(object li in lstOutcome.Items)
{
bulkCopy.DestinationTableName = "Customers";
//Amount to bulkcopy at once to prevent slowing with large imports.
bulkCopy.BatchSize = 200;
SqlBulkCopyColumnMapping map1 = new SqlBulkCopyColumnMapping(li.ToString(), "CustomerID");
bulkCopy.ColumnMappings.Add(map1);