Solved

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

Posted on 2009-04-02
2
389 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:FrancineTaylor
2 Comments
 
LVL 6

Accepted Solution

by:
SaedSalman earned 500 total points
ID: 24055853
> SQLObject current = (SQLObject)ddBindArray.SelectedItem;
Replaced with:
int index=ddBindArray.SelectedIndex;
SQLObject current=box[index];

but both box's ,ddBindArray's items must be in the same order.

Hope this help
0
 
LVL 1

Author Comment

by:FrancineTaylor
ID: 24057036

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?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now