Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select the selected index of a DropDown C#

Posted on 2007-03-23
6
Medium Priority
?
2,395 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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 …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…
Suggested Courses

715 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