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

Discussion in 'ASP .Net' started by =?Utf-8?B?S3Jpc3RpYW4=?=, Feb 7, 2005.

  1. 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
     
    =?Utf-8?B?S3Jpc3RpYW4=?=, Feb 7, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?S3Jpc3RpYW4=?=

    Karl Seguin Guest

    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

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Kristian" <> wrote in message
    news:D...
    > 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
     
    Karl Seguin, Feb 7, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    544
    titof
    Jul 24, 2003
  2. al
    Replies:
    1
    Views:
    325
    Victor Garcia Aprea [MVP]
    Apr 10, 2004
  3. Philip Meyer
    Replies:
    0
    Views:
    442
    Philip Meyer
    Nov 30, 2003
  4. QuantumG
    Replies:
    96
    Views:
    1,582
    Rob Thorpe
    Oct 26, 2004
  5. srikanth
    Replies:
    5
    Views:
    287
    Richard Heathfield
    Feb 28, 2006
Loading...

Share This Page