drop down list - how to force selected item

G

Geary

I have a drop down list on an asp.net 2 page that is bound to a table.
By default it displays the first item as the selected item. But I want
to make sure that the user must change the selection. I am using the
change-selection event to trigger so other code. If the user is
satisfied with the default this other code won't run. So I am adding an
additional .item.add("(None)") after the .databind() to add a (None)
selection to the list. The problem is that the (None) selection is at
the bottom of the list. How do I force the (None) selection to be the
initial selected item? Or is there a better way of doing this? If I
put the .item.add before the .databind, the (None)item is overwritten
with the bound data.
 
P

Peter Bucher [MVP]

Hello Geary
The problem is that the (None) selection is at the bottom of the list.
How do I force the (None) selection to be the initial selected item? Or
is there a better way of doing this? If I put the .item.add before the
.databind, the (None)item is overwritten with the bound data.
Set the Property "AppendDataBoundItems" to true.
This ensures that the additional item wouldnt be overwritten by
the databound data.

example code to add an item:
this.dropTest.Items.Add(new ListItem("---please choose---", "initial
value"));
 
G

Geary

It sounded right but still isn't doing what I need. I probably should
have given fuller detail.

I have 3 drop-down boxes kind of daisy-chained to together. The 1st is
for the department. In its change_selected event, I read it's new value
to determine what equipment list to load into the 2nd drop-down(equip).
Then once the user selects the equipment in that drop-down, I want the
3rd drop-down to display the models that run on the selected equipment.

The departments are hard-coded in the 1st list. When I change the
selected dept, the proper equipment appears in the 2nd list. But if the
initial displayed equipment happens to be the one that the user wants,
there is no change_selected event to trigger the loading the right model
numbers into the 3rd list.

When I tried the solution you sent. It appended the "please choose"
item and the new table data to the existing items already on the list.
I tried different arrangements of setting the .appendDataBoundItems back
and forth from true to false, to clear and then load the items in the
order I wanted, without success.

I remember back in the VB4 days of being about to manipulate the list
index to do things like this. I'm just not finding equivalent
functionary with the new stuff.
 
B

Brandon Gano

DropDownList has an AppendDataBoundItems property that needs to be set to
true. If you do that, you should be able to add the item before the databind
and retain the order you're looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top