473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.NullRefe renceException: 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.Select edItem
Line 85: UserName.Text = stUsers.Selecte dItem.Text
Line 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI.W ebControls.List Control.OnSelec tedIndexChang
ed(EventArgs e)

System.Web.UI.W ebControls.List Box.System.Web. UI.IPostBackD
ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()

Nov 17 '05 #1
10 2252
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.NullRefe renceException: 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.Select edItem
Line 85: UserName.Text = stUsers.Selecte dItem.Text
Line 86:
Line 87: 'Get the user details and fill textboxes

Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI.W ebControls.List Control.OnSelec tedIndexChang
ed(EventArgs e)

System.Web.UI.W ebControls.List Box.System.Web. UI.IPostBackD
ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()


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_Select edIndexChanged( ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles lstUsers.Select edIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException: 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.Select edItem
Line 85: UserName.Text = stUsers.Selecte dItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI.W ebControls.List Control.OnSelec tedIndexChang ed(EventArgs e)

System.Web.UI.W ebControls.List Box.System.Web. UI.IPostBackD ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()


.

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

TextBox1.Text = ListBox1.Select edValue()

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 "SelectedIndexC hanged" event i am
hoping that the "AutoPostBa ck" 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_Select edIndexChanged( ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles lstUsers.Select edIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Tex t = lstUsers.Select edItem.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.NullRefe renceException: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.Select edItem
Line 85: UserName.Text =stUsers.Select edItem.Text Line 86:
Line 87: 'Get the user details and filltextboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI. WebControls.Lis tControl.OnSele ctedIndexChang ed(EventArgs e)

System.Web.UI. WebControls.Lis tBox.System.Web .UI.IPostBackD ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()


.

.

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_Select edIndexChanged( ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles lstUsers.Select edIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException: 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.Select edItem
Line 85: UserName.Text = stUsers.Selecte dItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI.W ebControls.List Control.OnSelec tedIndexChang ed(EventArgs e)

System.Web.UI.W ebControls.List Box.System.Web. UI.IPostBackD ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()


.

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_Select edIndexChanged( ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles lstUsers.Select edIndexChanged

'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException: 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.Select edItem
Line 85: UserName.Text = stUsers.Selecte dItem.Text Line 86:
Line 87: 'Get the user details and fill textboxes
Source File: C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
Register\AssetR egister\ViewUse rs.aspx.vb:85

System.Web.UI.W ebControls.List Control.OnSelec tedIndexChang ed(EventArgs e)

System.Web.UI.W ebControls.List Box.System.Web. UI.IPostBackD ataHandler.Rais ePostDataChange dEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()


.

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

Code behind >>>>>

Private Sub ListBox1_Select edIndexChanged( ByVal sender As
System.Object, ByVal e As System.EventArg s)
Handles ListBox1.Select edIndexChanged
TextBox1.Text = ListBox1.Select edValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual
Basic .NET 7.1">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.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="T rue">
<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_Select edIndexChanged( ByVal senderAs Object, ByVal e As System.EventArg s) _
HandleslstUsers.Selec tedIndexChanged
'Need to bind the textboxes from the choice picked out
from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException:
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.Select edItem
>> Line 85: UserName.Text =
stUsers.Selecte dItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb Line: 85
>>
>> Stack Trace:
>>
>>
>> [NullReferenceEx ception: Object reference not setto an >> instance of an object.]
>>AssetRegister. ViewUser.lstUse rs_SelectedInde xChanged >> (Object sender, EventArgs e) in C:\Dev\AssetRegister >> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb:85
>>
>>
System.Web.UI. WebControls.Lis tControl.OnSele ctedIndexChang >> ed(EventArgs e)
>>
>>
System.Web.UI. WebControls.Lis tBox.System.Web .UI.IPostBackD >> ataHandler.Rais ePostDataChange dEvent()
>> System.Web.UI.P age.RaiseChange dEvents()
>> System.Web.UI.P age.ProcessRequ estMain()
>>
>>
>>
>>
>>
>
>
>.
>

.

.

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.W ebControls.List box.

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_Select edIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArg s)
Handles ListBox1.Select edIndexChanged
TextBox1.Text = ListBox1.Select edValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="VisualBasic .NET 7.1">
<meta name="vs_defaul tClientScript"
content="JavaS cript">
<meta name="vs_target Schema"
content="htt p://schemas.microso ft.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="T rue">
<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.gb l...
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_Select edIndexChanged( ByVal sender
As
Object, ByVal e As System.EventArg s) _
Handles

lstUsers.Sele ctedIndexChange d

'Need to bind the textboxes from the choice picked
out from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException:
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.Select edItem
>> Line 85: UserName.Text =
stUsers.Selecte dItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb Line: 85 >>
>> Stack Trace:
>>
>>
>> [NullReferenceEx ception: Object reference not set

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

AssetRegister .ViewUser.lstUs ers_SelectedInd exChanged
>> (Object sender, EventArgs e) in C:\Dev\Asset

Register
>> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb:85
>>
>>

System.Web.UI .WebControls.Li stControl.OnSel ectedIndexCha

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

System.Web.UI .WebControls.Li stBox.System.We b.UI.IPostBac kD
>> ataHandler.Rais ePostDataChange dEvent()
>> System.Web.UI.P age.RaiseChange dEvents()
>> System.Web.UI.P age.ProcessRequ estMain()
>>
>>
>>
>>
>>
>
>
>.
>
.

.

.

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.W ebControls.List box.

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_Select edIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArg s)
Handles ListBox1.Select edIndexChanged
TextBox1.Text = ListBox1.Select edValue()
End Sub

ASPX code >>>>>

<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="VisualBasic .NET 7.1">
<meta name="vs_defaul tClientScript"
content="JavaS cript">
<meta name="vs_target Schema"
content="htt p://schemas.microso ft.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="T rue">
<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.gb l...
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_Select edIndexChanged( ByVal sender
As
Object, ByVal e As System.EventArg s) _
Handles

lstUsers.Sele ctedIndexChange d

'Need to bind the textboxes from the choice picked
out from the list
UserName.Text = lstUsers.Select edItem.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.NullRefe renceException:
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.Select edItem
>> Line 85: UserName.Text =
stUsers.Selecte dItem.Text
>> Line 86:
>> Line 87: 'Get the user details and fill
textboxes
>>
>> Source File: C:\Dev\Asset Register
>> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb Line: 85 >>
>> Stack Trace:
>>
>>
>> [NullReferenceEx ception: Object reference not set

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

AssetRegister .ViewUser.lstUs ers_SelectedInd exChanged
>> (Object sender, EventArgs e) in C:\Dev\Asset

Register
>> SW\SourceCode\D otNet\ASP.NET\A SP.NET Asset
>> Register\AssetR egister\ViewUse rs.aspx.vb:85
>>
>>

System.Web.UI .WebControls.Li stControl.OnSel ectedIndexCha

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

System.Web.UI .WebControls.Li stBox.System.We b.UI.IPostBac kD
>> ataHandler.Rais ePostDataChange dEvent()
>> System.Web.UI.P age.RaiseChange dEvents()
>> System.Web.UI.P age.ProcessRequ estMain()
>>
>>
>>
>>
>>
>
>
>.
>
.

.

.

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.NullRefe renceException: 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.Selec tedItem
Line 85: UserName.Text = stUsers.Selecte dItem.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\Asset Register\ViewUs ers.aspx.vb Line: 85

Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
AssetRegister.V iewUser.lstUser s_SelectedIndex Changed
(Object sender, EventArgs e) in C:\Dev\Asset Register
SW\SourceCode\ DotNet\ASP.NET\ ASP.NET Asset
Register\Asset Register\ViewUs ers.aspx.vb:85

System.Web.UI. WebControls.Lis tControl.OnSele ctedIndexChan ged(EventArgs e)

System.Web.UI. WebControls.Lis tBox.System.Web .UI.IPostBack DataHandler.Rai sePostDataChang edEvent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()

.

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1284
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 box immediately. I have been able to work around this by clearing the box, adding a dummy string entry, and then clearing it again. Here is some code to demonstrate this:
1
3853
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
2878
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 a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
1
5316
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 not happenm , i have no clue what the problem is I am attaching the error <font color='red' >
2
3845
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: ------------------------------- ListBoxUser.Location = New System.Drawing.Point(16, 240) ListBoxUser.Name = "ListBoxUser" ListBoxUser.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended ListBoxUser.Size = New System.Drawing.Size(136, 147) ListBoxUser.TabIndex = 6
3
5112
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 this: -------------------------- Excel.Application xl = new Excel.ApplicationClass(); xl.Visible = "true"; String workbookPath = @"c:\SomeWorkBook.xls"; Excel.Workbook xlW = xlW.Workbooks.Open(workbookPath,0, false, 5, "",
2
9799
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 row into row object 2. Check one of the row columns against a dictionary key 3. If it's found, add it to the listbox. Then I want to pass the actual item that shows up in the listbox
4
4233
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 the 2 of them together. This is what I tried: Sub Page_Load(.....) Dim dInfo As DirectoryInfo dInfo = New DirectoryInfo(Server.MapPath(MyDir))
1
1989
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 displayed (without highlighting) when the field has a null value. The user may then change the displayed value by clicking on the up or down arrow to the right of the control. This newly displayed value will also be without highlighting and will be...
0
8987
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.