Solved

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

Posted on 2009-04-02
2
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save json data from URL using SSIS 1 72
CSS for Popup in ASP.NET 4 41
CSS question 16 59
Web Site Administration Tool - Security Questions 2 32
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

738 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