473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
10 2213
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ben | last post by:
Hi, I seem to be having a memory management issue with the ListBox control. Using .NET Memory Profiler, the Clear() method does not appear to actually remove references to objects in the list...
1
by: jarit | last post by:
Hi, Found these coding guidelines for C#, HTML, Javascript, Java, HTML, PL/SQL, T-SQL, VB and VBScript. Well written and free to download. www.demachina.com/products/swat Jeroen
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: Sachin Kuchinad | last post by:
Hi All I am using .NET Framework version 1.0.3705 to build a website. Now i have made a webform and on that i have added a dropdown to the page I bind this listbox to a datareader . This does...
2
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
3
by: Brent | last post by:
I'm trying to open and manipulate an Excel spreadsheet from C#. To that end, I've referenced Interop.EXCEL9.dll, which I have on my machine. All of the examples I've read say to do something like...
2
by: Pat | last post by:
I'm a newbie to c# and could use some help - been banging my head on the keyboard for 3 days now. I have an unbound listbox that I'm populating this way: 1. loop through a datatable and load...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: John | last post by:
Using Access 2007 I find that, on opening a form, a listbox control always displays one of the values in the list, even if no value has been selected. Thus, the first value in the list is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.