Solved

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

Posted on 2009-04-02
2
395 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

Industry Leaders: 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

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 …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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