DropDownList won't select item...

J

JamesW

Hi there.

Vstudio 2003, IE 6.0

I have an asp connected to an Access database.

A DropDownList on the page shows names from the Db.

When the user selects a name from the DropDownList I want the selected name
to appear in a text box on the page.

I have tried setting AutoPostBack etc. but the only selection to register is
always the first item in the list.

I have tried activating the selection by a button on the page too. (See Code
Below). Only the first item in the list is selected.

T.I.A for any help.

The Code:

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

Me.txtSelection.Text = Me.DropDownList1.SelectedItem.Text

End Sub

Private Sub btnSelectIt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSelectIt.Click

Me.lblSelection.Text = "You chose: " + DropDownList1.SelectedItem.Text


End Sub
 
P

Patrick.O.Ige

JamesW
Wrap the dropdownlist in the pageload and check for postback
Patrick
 
J

JamesW

Thanks Patrick that did the trick!

Code:
If Not IsPostBack Then

DropDownList1.DataSource = custName

DropDownList1.DataValueField = "CustID"

DropDownList1.DataTextField = "Name"

DropDownList1.SelectedIndex = -1

DropDownList1.DataBind()

End If
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top