467,136 Members | 1,393 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

Listbox & Object Not Referenced

yop
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.Text
Line 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedIn dexChang
ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.IP ostBackD
ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()

Nov 17 '05 #1
  • viewed: 1948
Share:
10 Replies
Unless an Item has been selected, this value will be null.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:0a****************************@phx.gbl...
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.Text
Line 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedIn dexChang
ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.IP ostBackD
ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()


Nov 17 '05 #2
yop
Kevin

I have an item selected alright, daft idea but could it
be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks
-----Original Message-----
Unless an Item has been selected, this value will be null.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:0a****************************@phx.gbl...
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedIn dexChang ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.IP ostBackD ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()


.

Nov 17 '05 #3
Try using .SelectedValue property.....

TextBox1.Text = ListBox1.SelectedValue()

If it fails too, i would check whether it is selected the
first time user comes on the web page. If that is also
set, and it is not working, i will try to see
whether "value" property returns anything. If that fails,
i have no idea why its not working.....

Since it is going to "SelectedIndexChanged" event i am
hoping that the "AutoPostBack" is set to true for your
control.

Thanks,

Tapasvi


-----Original Message-----
Kevin

I have an item selected alright, daft idea but could it
be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks
-----Original Message-----
Unless an Item has been selected, this value will be

null.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:0a****************************@phx.gbl...
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException:Object reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text =stUsers.SelectedItem.Text Line 86:
Line 87: 'Get the user details and filltextboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedI ndexChang ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.I PostBackD ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()


.

.

Nov 17 '05 #4
Is the ListBox's AutoPostBack property set to True?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:04****************************@phx.gbl...
Kevin

I have an item selected alright, daft idea but could it
be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks
-----Original Message-----
Unless an Item has been selected, this value will be

null.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:0a****************************@phx.gbl...
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedIn dexChang ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.IP ostBackD ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()


.

Nov 17 '05 #5
Another possiblity: Is the ListBox dynamically added to the Page?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:04****************************@phx.gbl...
Kevin

I have an item selected alright, daft idea but could it
be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks
-----Original Message-----
Unless an Item has been selected, this value will be

null.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:0a****************************@phx.gbl...
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedIn dexChang ed(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.IP ostBackD ataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()


.

Nov 17 '05 #6
Yes it is a property. Here is the code that works fine on
my machine.....

Code behind >>>>>

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual
Basic .NET 7.1">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:ListBox id="ListBox1"
style="Z-INDEX: 101; LEFT: 288px; POSITION: absolute; TOP:
168px"
runat="server"
Width="160px" Height="168px" AutoPostBack="True">
<asp:ListItem
Value="Tapasvi">Tapasvi</asp:ListItem>
<asp:ListItem Value="Tap
at Work">Tap at Work</asp:ListItem>
</asp:ListBox>
<asp:TextBox id="TextBox1"
style="Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP:
120px"

runat="server"></asp:TextBox>
</form>
</body>
</HTML>

Thanks,

Tap

-----Original Message-----
Aye it is set alright.

The SelectedValue is not a property of the listbox?
-----Original Message-----
Is the ListBox's AutoPostBack property set to True?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:04****************************@phx.gbl...
Kevin

I have an item selected alright, daft idea but could it
be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal senderAs Object, ByVal e As System.EventArgs) _
HandleslstUsers.SelectedIndexChanged
'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks

>-----Original Message-----
>Unless an Item has been selected, this value will be
null.
>
>--
>HTH,
>
>Kevin Spencer
>Microsoft MVP
>..Net Developer
>http://www.takempis.com
>The more I learn, the less I know.
>
>"yop" <yo*@oceanfree.net> wrote in message
>news:0a****************************@phx.gbl...
>> All
>>
>> When I try to get the text from my listbox I am getan >> error which is listed below.
>>
>> Any ideas?
>>
>> Thanks
>>
>> Object reference not set to an instance of anobject. >> Description: An unhandled exception occurred duringthe >> execution of the current web request. Please reviewthe >> stack trace for more information about the error and
>> where it originated in the code.
>>
>> Exception Details: System.NullReferenceException:
Object
>> reference not set to an instance of an object.
>>
>> Source Error:
>>
>>
>> Line 83: 'Need to bind the textboxes fromthe >> choice picked out from the list
>> Line 84: ' Dim ListItem As ListItem =
>> lstUsers.SelectedItem
>> Line 85: UserName.Text =
stUsers.SelectedItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb Line: 85
>>
>> Stack Trace:
>>
>>
>> [NullReferenceException: Object reference not setto an >> instance of an object.]
>>AssetRegister.ViewUser.lstUsers_SelectedIndexChan ged >> (Object sender, EventArgs e) in C:\Dev\AssetRegister >> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb:85
>>
>>
System.Web.UI.WebControls.ListControl.OnSelectedI ndexChang >> ed(EventArgs e)
>>
>>
System.Web.UI.WebControls.ListBox.System.Web.UI.I PostBackD >> ataHandler.RaisePostDataChangedEvent()
>> System.Web.UI.Page.RaiseChangedEvents()
>> System.Web.UI.Page.ProcessRequestMain()
>>
>>
>>
>>
>>
>
>
>.
>

.

.

Nov 17 '05 #7
yop
No the listbox is added at design time but the items are
added from the DB at run time. Maybe that is an issue.
Extremely frustating!! :(

Also the selectedvalue property is telling it is "not a
member of System.Web.UI.WebControls.Listbox.

I am using Framework 1.1, there is an issue with using
the webcontrols and this version I think??

Would I be better of using a 3rd party list or data list
or something?

-----Original Message-----
Yes it is a property. Here is the code that works fine onmy machine.....

Code behind >>>>>

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="VisualBasic .NET 7.1">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:ListBox id="ListBox1"
style="Z-INDEX: 101; LEFT: 288px; POSITION: absolute; TOP:168px"
runat="server"
Width="160px" Height="168px" AutoPostBack="True">
<asp:ListItem
Value="Tapasvi">Tapasvi</asp:ListItem>
<asp:ListItem Value="Tap
at Work">Tap at Work</asp:ListItem>
</asp:ListBox>
<asp:TextBox id="TextBox1"
style="Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP:120px"

runat="server"></asp:TextBox>
</form>
</body>
</HTML>

Thanks,

Tap

-----Original Message-----
Aye it is set alright.

The SelectedValue is not a property of the listbox?
-----Original Message-----
Is the ListBox's AutoPostBack property set to True?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:04****************************@phx.gbl.. .
Kevin

I have an item selected alright, daft idea but could it be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender
As
Object, ByVal e As System.EventArgs) _
Handles

lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked
out from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks

>-----Original Message-----
>Unless an Item has been selected, this value will be
null.
>
>--
>HTH,
>
>Kevin Spencer
>Microsoft MVP
>..Net Developer
>http://www.takempis.com
>The more I learn, the less I know.
>
>"yop" <yo*@oceanfree.net> wrote in message
>news:0a****************************@phx.gbl...
>> All
>>
>> When I try to get the text from my listbox I am get
an
>> error which is listed below.
>>
>> Any ideas?
>>
>> Thanks
>>
>> Object reference not set to an instance of an

object.
>> Description: An unhandled exception occurred
duringthe
>> execution of the current web request. Please
reviewthe
>> stack trace for more information about the error

and >> where it originated in the code.
>>
>> Exception Details: System.NullReferenceException:
Object
>> reference not set to an instance of an object.
>>
>> Source Error:
>>
>>
>> Line 83: 'Need to bind the textboxes from

the
>> choice picked out from the list
>> Line 84: ' Dim ListItem As ListItem =
>> lstUsers.SelectedItem
>> Line 85: UserName.Text =
stUsers.SelectedItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb Line: 85 >>
>> Stack Trace:
>>
>>
>> [NullReferenceException: Object reference not set

to an
>> instance of an object.]
>>

AssetRegister.ViewUser.lstUsers_SelectedIndexCha nged
>> (Object sender, EventArgs e) in C:\Dev\Asset

Register
>> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb:85
>>
>>

System.Web.UI.WebControls.ListControl.OnSelected IndexCha

ng
>> ed(EventArgs e)
>>
>>

System.Web.UI.WebControls.ListBox.System.Web.UI. IPostBac kD
>> ataHandler.RaisePostDataChangedEvent()
>> System.Web.UI.Page.RaiseChangedEvents()
>> System.Web.UI.Page.ProcessRequestMain()
>>
>>
>>
>>
>>
>
>
>.
>
.

.

.

Nov 17 '05 #8
yop
No the listbox is added at design time but the items are
added from the DB at run time. Maybe that is an issue.
Extremely frustating!! :(

Also the selectedvalue property is telling it is "not a
member of System.Web.UI.WebControls.Listbox.

I am using Framework 1.1, there is an issue with using
the webcontrols and this version I think??

Would I be better of using a 3rd party list or data list
or something?

-----Original Message-----
Yes it is a property. Here is the code that works fine onmy machine.....

Code behind >>>>>

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="VisualBasic .NET 7.1">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:ListBox id="ListBox1"
style="Z-INDEX: 101; LEFT: 288px; POSITION: absolute; TOP:168px"
runat="server"
Width="160px" Height="168px" AutoPostBack="True">
<asp:ListItem
Value="Tapasvi">Tapasvi</asp:ListItem>
<asp:ListItem Value="Tap
at Work">Tap at Work</asp:ListItem>
</asp:ListBox>
<asp:TextBox id="TextBox1"
style="Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP:120px"

runat="server"></asp:TextBox>
</form>
</body>
</HTML>

Thanks,

Tap

-----Original Message-----
Aye it is set alright.

The SelectedValue is not a property of the listbox?
-----Original Message-----
Is the ListBox's AutoPostBack property set to True?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"yop" <yo*@oceanfree.net> wrote in message
news:04****************************@phx.gbl.. .
Kevin

I have an item selected alright, daft idea but could it be something to do with postback or something?

I click on the item and call the following:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender
As
Object, ByVal e As System.EventArgs) _
Handles

lstUsers.SelectedIndexChanged

'Need to bind the textboxes from the choice picked
out from the list
UserName.Text = lstUsers.SelectedItem.Text
thanks

>-----Original Message-----
>Unless an Item has been selected, this value will be
null.
>
>--
>HTH,
>
>Kevin Spencer
>Microsoft MVP
>..Net Developer
>http://www.takempis.com
>The more I learn, the less I know.
>
>"yop" <yo*@oceanfree.net> wrote in message
>news:0a****************************@phx.gbl...
>> All
>>
>> When I try to get the text from my listbox I am get
an
>> error which is listed below.
>>
>> Any ideas?
>>
>> Thanks
>>
>> Object reference not set to an instance of an

object.
>> Description: An unhandled exception occurred
duringthe
>> execution of the current web request. Please
reviewthe
>> stack trace for more information about the error

and >> where it originated in the code.
>>
>> Exception Details: System.NullReferenceException:
Object
>> reference not set to an instance of an object.
>>
>> Source Error:
>>
>>
>> Line 83: 'Need to bind the textboxes from

the
>> choice picked out from the list
>> Line 84: ' Dim ListItem As ListItem =
>> lstUsers.SelectedItem
>> Line 85: UserName.Text =
stUsers.SelectedItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb Line: 85 >>
>> Stack Trace:
>>
>>
>> [NullReferenceException: Object reference not set

to an
>> instance of an object.]
>>

AssetRegister.ViewUser.lstUsers_SelectedIndexCha nged
>> (Object sender, EventArgs e) in C:\Dev\Asset

Register
>> SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
>> Register\AssetRegister\ViewUsers.aspx.vb:85
>>
>>

System.Web.UI.WebControls.ListControl.OnSelected IndexCha

ng
>> ed(EventArgs e)
>>
>>

System.Web.UI.WebControls.ListBox.System.Web.UI. IPostBac kD
>> ataHandler.RaisePostDataChangedEvent()
>> System.Web.UI.Page.RaiseChangedEvents()
>> System.Web.UI.Page.ProcessRequestMain()
>>
>>
>>
>>
>>
>
>
>.
>
.

.

.

Nov 17 '05 #9
yop
eventually found the fix after trawling the forums!!

"I was loading the listbox dynamically on the page_load
event.
Eventually I discovered - that was too late,
The items showed on the page but weren't really
there..... (figure that one
out)
When I moved the list populate routine to the page_init
event everything
worked great."

Thanks for all your help
-----Original Message-----
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.TextLine 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedI ndexChan ged(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.I PostBack DataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()

.

Nov 17 '05 #10
yop
eventually found the fix after trawling the forums!!

"I was loading the listbox dynamically on the page_load
event.
Eventually I discovered - that was too late,
The items showed on the page but weren't really
there..... (figure that one
out)
When I moved the list populate routine to the page_init
event everything
worked great."

Thanks for all your help
-----Original Message-----
All

When I try to get the text from my listbox I am get an
error which is listed below.

Any ideas?

Thanks

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 83: 'Need to bind the textboxes from the
choice picked out from the list
Line 84: ' Dim ListItem As ListItem =
lstUsers.SelectedItem
Line 85: UserName.Text = stUsers.SelectedItem.TextLine 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb Line: 85

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
AssetRegister.ViewUser.lstUsers_SelectedIndexChang ed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\DotNet\ASP.NET\ASP.NET Asset
Register\AssetRegister\ViewUsers.aspx.vb:85

System.Web.UI.WebControls.ListControl.OnSelectedI ndexChan ged(EventArgs e)

System.Web.UI.WebControls.ListBox.System.Web.UI.I PostBack DataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()

.

Nov 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jarit@xs4all.nl | last post: by
6 posts views Thread by Chris Leuty | last post: by
3 posts views Thread by Brent | last post: by
4 posts views Thread by rn5a@rediffmail.com | last post: by
1 post views Thread by John | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.