Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ListBox index values

Reply
Thread Tools

ListBox index values

 
 
=?Utf-8?B?TmlnZ3k=?=
Guest
Posts: n/a
 
      06-03-2005
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.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?c3Jpbmk=?=
Guest
Posts: n/a
 
      06-03-2005
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.
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TmlnZ3k=?=
Guest
Posts: n/a
 
      06-03-2005
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.
> >
> >

 
Reply With Quote
 
=?Utf-8?B?c3Jpbmk=?=
Guest
Posts: n/a
 
      06-03-2005
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.
> > >
> > >

 
Reply With Quote
 
=?Utf-8?B?TmlnZ3k=?=
Guest
Posts: n/a
 
      06-03-2005
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.
> > > >
> > > >

 
Reply With Quote
 
=?Utf-8?B?c3Jpbmk=?=
Guest
Posts: n/a
 
      06-03-2005
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.
> > > > >
> > > > >

 
Reply With Quote
 
=?Utf-8?B?TmlnZ3k=?=
Guest
Posts: n/a
 
      06-03-2005
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.
> > > > > >
> > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
Listbox item added with client scripts not submitting with ASP:Listbox Simon Prince ASP .Net 2 10-19-2004 04:11 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments