views:

2427

answers:

2

Hello,

I have a form that contains a GridView control which is databound to an ObjectDataSource Control. There are several TextBox controls that are already being used as ControlParameters for the ObjectDataSource. I also have a custom data object that the ObjectDataSource is associated with {TypeName="myDataClass"}. The values are passed from the ObjectDataSource to myDataClass.

Now I need to also use a multi-select ListBox as a ControlParameter. When I use the SelectedValue parameter of the ListBox, the ObjectDataSource is only seeing the first selected item in the list.

Here's the question: How can I get all the multi-select ListBox values passed into my custom object "myDataClass" instead of just the first one selected? Hence the ["multi-select"]

Thanks for any help!

+2  A: 

Multi-select list boxes are tricky. You need to loop through the items in code to build a list of selected values. So you will probably need to implement a custom parameter that does this for you.

You might end up needing to bind to the grid from code-behind, instead of doing it declaratively.

Eric Z Beard
Thank you for the answer. I figured that was the case. What I did was created a Web User Control with some custom properties to expose the multiple values(CSV in my case) of the multi-select Listbox. The ObjectDataSource was then able to use the values with no problem.
M3NTA7
A: 

This is typical problem. multi-select list box always return the first selected value and not all the selected value. We have to loop through the entire collection and check each individual value if selected or not.

Alok http://www.extendcode.com

Alok Kumar