[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2009-04-02
2
Medium Priority
?
399 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 2000 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

Technology Partners: 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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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