Link to home
Start Free TrialLog in
Avatar of FrancineTaylor
FrancineTaylor

asked on

How to get the selected item from a dropdown box bound to an array of custom objects

I create an array of custom objects and bind it to a dropdown box.

SQLObject[] boxes = new SQLObject[] {
      new SQLObject(eRecordType.EMPLOYEE, "SELECT TOP 15 * FROM dbo.Employee"),
      new SQLObject(eRecordType.LOGGER, "SELECT TOP 15 * FROM dbo.Logger")};
ddBindArray.DataSource = boxes;
ddBindArray.DataBind();

Then in the selected index changed event, I want to get the item selected:

protected void ddBindArray_SelectedIndexChanged(object sender, EventArgs e) {

   I tried getting the selected item and casting it...
       SQLObject current = (SQLObject)ddBindArray.SelectedItem;

   I also tried getting the indexed item
       SQLObject current = (SQLObject)ddBindArray.Items[ddBindArray.SelectedIndex];

..but both times I got this error at compile time:

Cannot convert type 'System.Web.UI.WebControls.ListItem' to 'SQLObject'

How can I get the object selected without having to store the original array and refer back to it?
ASKER CERTIFIED SOLUTION
Avatar of SaedSalman
SaedSalman
Flag of Jordan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FrancineTaylor
FrancineTaylor

ASKER


What I was actually looking for is a way to bind the array (or collection) of objects to a control such that I wouldn't have to store and retrieve (probably with Session) the original collection.

When I bind an array to a client control, does that array exist client-side, or does the control only contain the strings which it displays?