Databinding a multiselect ListBox in a FormView control

Posted by drs9222 on Stack Overflow See other posts from Stack Overflow or by drs9222
Published on 2010-04-14T18:29:05Z Indexed on 2010/04/14 21:03 UTC
Read the original article Hit count: 1257

I have a multiselect ListBox within a FormView. I can't figure out how to setup the databinding for it.
I can populate the listbox fine. If the listbox was a single select I could use say SelectValue='<%#Bind("col")%>' and that works fine. Is there something that I can bind to for a multiselect listbox? I've tried manually DataBinding by handling the DataBinding event of the listbox and setting the selected property on the appropriate items. Unfortunately, there are no items in the listbox during the DataBinding event. The closest thing I've found is to save the value that determines what items should be selecting during DataBinding and then use that value in the FormViews DataBinding event to select the right items which seems like a hack to me.

Is there a better way?


EDIT:

To clarify what I am currently doing...

I am using the FormViews's ItemCreated event to save the FormView's DataItem. Then in the FormView's DataBound event I find the listbox and manually set the selected items. It doesn't seem right that I have to save the value like this and I assume there is a more correct way to do this that I just can't see.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about listbox