Solved

Select the selected index of a DropDown C#

Posted on 2007-03-23
6
2,368 Views
Last Modified: 2012-05-05
Hello Experts,
I have a curious problem.  I am coding in C#.
I have a number of DropDown lists on an aspx page.  By default the selected index of all DropDowns is 0 or the first item in the list.  My problem is that I want the user to be able to select the first item in the DropDown.  I have all of the DropDowns bound and rebound depending on the selections the user makes.  Each time a value is changed a new Datasource is created showing only the items that are remaining based on the previous selections.  So basically my question is how do I select the already selected item in a DropDown list to fire off the SelectedIndexChanged event to code on?
0
Comment
Question by:Glowman
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:ethoths
ID: 18780945
What I usually do hwere is put a dummy item as the first item, sort of "Please Select...".
When the user selects this I remove this item from the list (clinet side if it does not cause a postback, server if it does).

0
 
LVL 4

Author Comment

by:Glowman
ID: 18781044
That is what I thought of doing, but it isn't going to work in my situation since the query used to recreate the list is going to be regenerated each time any selection is made for all drop down lists (15).  So if I do want to add a "Please Select .." it would be on the bottom of the list, since if I put it before I bind it just goes away.  I really just need to reset the selectedindex each time a drop down is even touched.  Is there a click() event or anything I can use?
0
 
LVL 11

Expert Comment

by:ethoths
ID: 18781136
In the pre-render just insert the list item at position 0.
If you do thios at the page level (rather than the control) you might need to use the prerendercomplete event instead as the controls are databound.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:Glowman
ID: 18781743
The only event I have at my disposal is PreRender().
Do I need to create my own event?
is there a way to do this client side to trigger a server side event?
I really would like to avoid the "Please select .." option if possible.
0
 
LVL 11

Accepted Solution

by:
ethoths earned 250 total points
ID: 18791401
The problem is that you want to allow the user to click on the already selected item and have that count as making a selection. You could use the onclick event to do that but it would mean that the event gets fired when your user tries to drop down the list and select another item.

I've been doing this type of thing for years an the 'Please select...' tactic is the only suitable one I've come across.
0
 
LVL 4

Author Comment

by:Glowman
ID: 18792914
Alright, I will stop being so stubborn!
Thanks for your help ethoths.
I really appreciate it.
G
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

19 Experts available now in Live!

Get 1:1 Help Now