views:

253

answers:

2

I am using Asp.net 3.5, C#, Visual Studio 2008. Ok, so I admit I am being really lazy here, but I know there's got to be a way to do this.

I have 2 identical listviews - listview1 and listview2. There is a checkbox in column 1 of both listviews, and a button on the page.

I would like to copy the rows that are checked in listview1 to listview2 when the button is pressed.

I know how to do this by looping thru listview1, but how can I do it in one step using an ObjectDataSource?

A: 

perhaps some linq magic, something like

var data = listView1.Items.Where(i=> i.selected == true);

viewlist2.DataSource = data;
viewlist2.DataBind();

I do not have VS right now, so this code is just from the top of my head and im not sure if the properties are named like that, or if you can use a where directly on Items or if you have to do a .ToList fist

Francisco Noriega
A: 

Implement a method in the class where you already have your ObjectDataSource-Methods. In the Button Click Handler find out, which items are selected and pass them to the Copy method.

This copy method should provide the necessary logic to perform operations with the underlying data the DataObjectSource is using.

Afterwards perform a manually .DataBind() on both ListViews to ensure latest data.

citronas