Drop Down List Control

M

Martyn Fewtrell

Hi There

I apologise for this one as I am sure that it is pretty straight forward.

I am using VB.NET in ASP and have loaded a drop down list from the
database - No problem so far!

I then want to set the selected value of the list using a text value from
elsewhere so that the drop down list displays the correct value when the
page is opened.

Currently using

dropdownlist.SelectedItem.Text = literal.text

where the literal holds the value that I want selected.

This seems to be changing the text value of the selected item to that of the
literal value rather than selecting the correct item from the list and
setting the selected value to the correct selection.

Hope this makes sense.

Martyn Fewtrell
 
M

Mike Moore [MSFT]

Hi Martyn,

Try this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DropDownList1.Items.Add("a")
DropDownList1.Items.Add("b")
DropDownList1.Items.Add("c")
DropDownList1.Items.FindByText("b").Selected = True
End Sub

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top