Solved

Select the selected index of a DropDown C#

Posted on 2007-03-23
6
2,374 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
[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
  • 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
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!

 
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

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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