Thursday, March 22, 2012

Listbox binding to objectdatasource using foreach statement

I have a listbox that has already been populated with items and want to take those items and add them to table.

I trying to add them with a foreach statement.

if

(ListBox2.Items.FindByText(strSelection) ==null)

{

foreach (ListItem itemin ListBox2.Items)

{

ObjectDataSource2.Insert(LocationName);

}

}

While im not 100% sure what you are actually trying to accomplish, but im also confused by 'ObjectDataSource2.Insert(LocationName);'.What is LocationName? Are you trying to add a column to your table called LocationName? or trying to add the items in the list box to be displayed with the rest of the data in the datasource?

I was trying to use microsoft 2.0 solution of building controls and using the objectdataadapter that lets you create the select, update, insert and delect methods. I have listbox with multilpe selected items in it that I want to associate it with userid and username.

something like, where userid and username would never change but new rows would be added for locationname that coming from the listbox

userid username locationname

1 john1 seattle

1 john1 greenlake

0 comments:

Post a Comment