DropDown List Default Selected Item

K

Kris Rockwell

Hello (again),

I have gotten the dropdown list functionality to work through a few tricks
(probably not the most efficient, but it works) but I am not sure how to set
the default selected value. I have tried setting various values to represent
the default value with little success. Essentially I am looking to have the
first item in the list be the default selected item. I noticed in the
properties for a dtat grid you could set a default selected index
(DataGrid.SelectedIndex =). Is there a similiar property for the Dropdown
list that I am just not seeing?

DropDownList.SelectedIndex = 0 does not seem to work.

Regards,
Kris
 
K

Kris Rockwell

Well, it seems although I set the property as follows:

DropDownList.SelectedIndex = 0

the selected value is not passed. If I try to get the value after setting
this I no return (although I do see the associsted text in the DDList).
However, if I select a different value and then select the initial value it
does retuen the index.

Regards,
Kris
 
D

Dan Brussee

Just being sure. You mention checking the value. The SelectedValue is
quite different than the SelectedIndex. Setting the SelectedIndex to 0
will select the first item in the dropdown list. It will have both a
Value and Text property as well.
 
K

Kris Rockwell

Following what you have said, setting the code as follows should produce the
correct results.

...Omitted Connection, data adapter and Dataset info...

DropDownList.DataBind()
DropDownList.SelectedIndex = 0

In this instance the first item in the list should be selected by default
without any user interaction.

Is that a correct assumption?

Regards,
Kris
 
D

Dan Brussee

Looks right to me.

Following what you have said, setting the code as follows should produce the
correct results.

..Omitted Connection, data adapter and Dataset info...

DropDownList.DataBind()
DropDownList.SelectedIndex = 0

In this instance the first item in the list should be selected by default
without any user interaction.

Is that a correct assumption?

Regards,
Kris
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top