ObjectContainerDataSource and DropDownList

Nov 5, 2007 at 2:56 AM
I would like to use ObjectContainerDataSource as data source to DropDownList. After that on button click event I would like to get entity instance which is currently selected in dropdown.

Please let me know how to do this.
Nov 9, 2007 at 6:04 PM
Hi

What you could do is bind the ObjectContainerDataSource to the DropDownList, like this:
<asp:DropDownList ID="MyDropDownList" runat="server" DataSourceID="MyObjectContainerDataSource" DataTextField="Name" DataValueField="Id" AutoPostBack="True"></asp:DropDownList>
 
<pp:ObjectContainerDataSource ID="MyObjectContainerDataSource" runat="server" DataObjectTypeName="MyProject.MyModule.MyEntity" />
DataTextField sets the field to display and DataValueField sets which field to use as a reference for the displaying of the DataTextField. In the example above, the DropDownList will display Names by Id.

Regarding the instance retrieval, you may search the selected item in the DropDownList in the ObjectContainerDataSource.Items collection.

Please let me know if this helps.

Ignacio Baumann Fonay
http://staff.southworks.net/blogs/ibaumann/
Nov 9, 2007 at 8:45 PM
Thank you.

I know how to bind DropDownList to ObjectContainerDataSource. What I want is code which retrives entities which are selected in ListBox or DropDown.
Nov 9, 2007 at 10:44 PM
Mahesh, I don't understand clearly what you need. but does the following help
If trying to access on client side.
Use $get to get the combobox and iterate through the options
for ( var j = 0 ; j < combo.options.length; j++) {
if ( combo.optionsj.selected == true ) {
// Do what ever you need to do
}
}

If on server side. Do the same with the items collection of the combo box.
Jul 30, 2008 at 11:57 AM
Hi Everybody.

I was looking for a solution for my issue and I've found that post wich has a similar issue, but I couldn't solved.

I have a DetailsView within a template fields called "Customers" which is a DropDownList (DDL) binded to an ObjectContainerDataSource of an Business Entity "Customer". DDL is populated when I load that page, but when I click on the Insert button and Inserted event is raised I get null value on the atribute Customer of e.Instance.

How could I bind that object, to the "primary" object of the data source.

I don't know if i've explained as well as i whish.

Thanks in advance.
Sergio