ListBox index values

Discussion in 'ASP .Net' started by =?Utf-8?B?TmlnZ3k=?=, Jun 3, 2005.

  1. Hi there,

    I would like to display the values of the index as chosen by the user in a
    listbox. These values would be as per the datavaluefield. On testing I get
    a value of -1:

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    Me.Label1.Text = ListBox1.Items.Item(2).Text
    End Sub

    I would like to replace the "2" with the item the user selects. Any help
    appreciated.
     
    =?Utf-8?B?TmlnZ3k=?=, Jun 3, 2005
    #1
    1. Advertising

  2. hi,
    you can get the selected value of the listbox at the server side using
    ListBox1.SelectedItem.Value .
    so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    --
    The best
    srini
    http://www.expertszone.com


    "Niggy" wrote:

    > Hi there,
    >
    > I would like to display the values of the index as chosen by the user in a
    > listbox. These values would be as per the datavaluefield. On testing I get
    > a value of -1:
    >
    > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > End Sub
    >
    > I would like to replace the "2" with the item the user selects. Any help
    > appreciated.
    >
    >
     
    =?Utf-8?B?c3Jpbmk=?=, Jun 3, 2005
    #2
    1. Advertising

  3. Thanks but I get an error:

    Object reference not set to an instance of an object.


    "srini" wrote:

    > hi,
    > you can get the selected value of the listbox at the server side using
    > ListBox1.SelectedItem.Value .
    > so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    > --
    > The best
    > srini
    > http://www.expertszone.com
    >
    >
    > "Niggy" wrote:
    >
    > > Hi there,
    > >
    > > I would like to display the values of the index as chosen by the user in a
    > > listbox. These values would be as per the datavaluefield. On testing I get
    > > a value of -1:
    > >
    > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > > End Sub
    > >
    > > I would like to replace the "2" with the item the user selects. Any help
    > > appreciated.
    > >
    > >
     
    =?Utf-8?B?TmlnZ3k=?=, Jun 3, 2005
    #3
  4. hi niggy,
    are you binding the listbox at runtime? if so check that the listbox has
    items after postback.. you are getting this error probably becoz the listbox
    has no selected item.i think you are binding the listbox on postback.
    --
    The best
    srini
    http://www.expertszone.com


    "Niggy" wrote:

    > Thanks but I get an error:
    >
    > Object reference not set to an instance of an object.
    >
    >
    > "srini" wrote:
    >
    > > hi,
    > > you can get the selected value of the listbox at the server side using
    > > ListBox1.SelectedItem.Value .
    > > so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    > > --
    > > The best
    > > srini
    > > http://www.expertszone.com
    > >
    > >
    > > "Niggy" wrote:
    > >
    > > > Hi there,
    > > >
    > > > I would like to display the values of the index as chosen by the user in a
    > > > listbox. These values would be as per the datavaluefield. On testing I get
    > > > a value of -1:
    > > >
    > > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > > > End Sub
    > > >
    > > > I would like to replace the "2" with the item the user selects. Any help
    > > > appreciated.
    > > >
    > > >
     
    =?Utf-8?B?c3Jpbmk=?=, Jun 3, 2005
    #4
  5. I have autopostback=true and listbox1.databind() on page load. What now?

    "srini" wrote:

    > hi niggy,
    > are you binding the listbox at runtime? if so check that the listbox has
    > items after postback.. you are getting this error probably becoz the listbox
    > has no selected item.i think you are binding the listbox on postback.
    > --
    > The best
    > srini
    > http://www.expertszone.com
    >
    >
    > "Niggy" wrote:
    >
    > > Thanks but I get an error:
    > >
    > > Object reference not set to an instance of an object.
    > >
    > >
    > > "srini" wrote:
    > >
    > > > hi,
    > > > you can get the selected value of the listbox at the server side using
    > > > ListBox1.SelectedItem.Value .
    > > > so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    > > > --
    > > > The best
    > > > srini
    > > > http://www.expertszone.com
    > > >
    > > >
    > > > "Niggy" wrote:
    > > >
    > > > > Hi there,
    > > > >
    > > > > I would like to display the values of the index as chosen by the user in a
    > > > > listbox. These values would be as per the datavaluefield. On testing I get
    > > > > a value of -1:
    > > > >
    > > > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > > > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > > > > End Sub
    > > > >
    > > > > I would like to replace the "2" with the item the user selects. Any help
    > > > > appreciated.
    > > > >
    > > > >
     
    =?Utf-8?B?TmlnZ3k=?=, Jun 3, 2005
    #5
  6. in the page load check for postback like
    If Not Page.IsPostBack Then
    --
    code for binding the list box here
    --
    End If
    --
    The best
    srini
    http://www.expertszone.com


    "Niggy" wrote:

    > I have autopostback=true and listbox1.databind() on page load. What now?
    >
    > "srini" wrote:
    >
    > > hi niggy,
    > > are you binding the listbox at runtime? if so check that the listbox has
    > > items after postback.. you are getting this error probably becoz the listbox
    > > has no selected item.i think you are binding the listbox on postback.
    > > --
    > > The best
    > > srini
    > > http://www.expertszone.com
    > >
    > >
    > > "Niggy" wrote:
    > >
    > > > Thanks but I get an error:
    > > >
    > > > Object reference not set to an instance of an object.
    > > >
    > > >
    > > > "srini" wrote:
    > > >
    > > > > hi,
    > > > > you can get the selected value of the listbox at the server side using
    > > > > ListBox1.SelectedItem.Value .
    > > > > so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    > > > > --
    > > > > The best
    > > > > srini
    > > > > http://www.expertszone.com
    > > > >
    > > > >
    > > > > "Niggy" wrote:
    > > > >
    > > > > > Hi there,
    > > > > >
    > > > > > I would like to display the values of the index as chosen by the user in a
    > > > > > listbox. These values would be as per the datavaluefield. On testing I get
    > > > > > a value of -1:
    > > > > >
    > > > > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > > > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > > > > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > > > > > End Sub
    > > > > >
    > > > > > I would like to replace the "2" with the item the user selects. Any help
    > > > > > appreciated.
    > > > > >
    > > > > >
     
    =?Utf-8?B?c3Jpbmk=?=, Jun 3, 2005
    #6
  7. Brilliant! Thanks.

    "srini" wrote:

    > in the page load check for postback like
    > If Not Page.IsPostBack Then
    > --
    > code for binding the list box here
    > --
    > End If
    > --
    > The best
    > srini
    > http://www.expertszone.com
    >
    >
    > "Niggy" wrote:
    >
    > > I have autopostback=true and listbox1.databind() on page load. What now?
    > >
    > > "srini" wrote:
    > >
    > > > hi niggy,
    > > > are you binding the listbox at runtime? if so check that the listbox has
    > > > items after postback.. you are getting this error probably becoz the listbox
    > > > has no selected item.i think you are binding the listbox on postback.
    > > > --
    > > > The best
    > > > srini
    > > > http://www.expertszone.com
    > > >
    > > >
    > > > "Niggy" wrote:
    > > >
    > > > > Thanks but I get an error:
    > > > >
    > > > > Object reference not set to an instance of an object.
    > > > >
    > > > >
    > > > > "srini" wrote:
    > > > >
    > > > > > hi,
    > > > > > you can get the selected value of the listbox at the server side using
    > > > > > ListBox1.SelectedItem.Value .
    > > > > > so try using Me.Label1.Text = ListBox1.SelectedItem.Value
    > > > > > --
    > > > > > The best
    > > > > > srini
    > > > > > http://www.expertszone.com
    > > > > >
    > > > > >
    > > > > > "Niggy" wrote:
    > > > > >
    > > > > > > Hi there,
    > > > > > >
    > > > > > > I would like to display the values of the index as chosen by the user in a
    > > > > > > listbox. These values would be as per the datavaluefield. On testing I get
    > > > > > > a value of -1:
    > > > > > >
    > > > > > > Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
    > > > > > > ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    > > > > > > Me.Label1.Text = ListBox1.Items.Item(2).Text
    > > > > > > End Sub
    > > > > > >
    > > > > > > I would like to replace the "2" with the item the user selects. Any help
    > > > > > > appreciated.
    > > > > > >
    > > > > > >
     
    =?Utf-8?B?TmlnZ3k=?=, Jun 3, 2005
    #7
    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. blenderdude
    Replies:
    0
    Views:
    1,150
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    421
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    909
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,384
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    357
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page