A clearly instansiated object (a WebForm control) isn't instansiat

G

Guest

Hello,
When clicking on a button the selected item from the 1st listbox is supposed
to be added to the 2nd listbox:
The code:
Private Sub btnInfo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInfo.Click
Dim sVal As String
Me.lstKatInfo.SelectedIndex = -1
sVal = Me.lstKat.SelectedItem.Text
Me.lstKatInfo.Items.Add(sVal)
End Sub

When I enter text values in the first listbox everything works fine, but
when the
listbox items are added in the Page_Load event from a DataTable
this problems occurs.
Any ideas?

Thanks in advance,
Kristian
 
K

Karl Seguin

Kristian:
Are you rebinding the listbox on postback? My guess is that you are, and
therefore the user's selection is being overwritten with blank.

if not page.IsPOstBack then
lstKat.DataSource = myDataTable
lstKat.DataBind()
end if

also, in your btnInfo_Click you rally should make sure that there is a
selected item before retriving it's text...

Karl
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top