Solved

Select the selected index of a DropDown C#

Posted on 2007-03-23
6
2,372 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

809 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