Solved

Select the selected index of a DropDown C#

Posted on 2007-03-23
6
2,366 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

20 Experts available now in Live!

Get 1:1 Help Now