Showing posts with label item. Show all posts
Showing posts with label item. Show all posts

Saturday, March 24, 2012

Object reference not set to an instance of an object

Hello All!

I get this error at this line
Line 368: Len(e.Item.Cells(5).Text) - 1)
Line 369: txtQty.Text = e.Item.Cells(5).Text
****Line 370: chkEbay.Checked =
CType(e.Item.Cells(6).FindControl("chkEbay"), _****
Line 371: CheckBox).Checked
Line 372: chkSold.Checked =
CType(e.Item.Cells(7).FindControl("chkSold"), _

It comes up when I hit the Edit button on my data grid, here is my code for
that sub. Any thoughts?

Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
grdUinv.ItemCommand

If e.Item.ItemType = ListItemType.Pager Or _
e.Item.ItemType = ListItemType.Header Then Exit Sub
grdUinv.EditItemIndex = -1

Dim btn As Button = CType(e.CommandSource, Button)
If btn.Text = "Edit" Then
txbProductID.Text = e.Item.Cells(0).Text
txtProdName.Text = e.Item.Cells(1).Text
txtModNum.Text = e.Item.Cells(2).Text
txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text, _
Len(e.Item.Cells(4).Text) - 1)
txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text, _
Len(e.Item.Cells(5).Text) - 1)
txtQty.Text = e.Item.Cells(5).Text
chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"), _
CheckBox).Checked
chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"), _
CheckBox).Checked
pnlAdd.Visible = True
Else
' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToSt ring)

End If
btnSave.CommandArgument = ""
End Sub

TIA!!!

RudyHi Rudy:

You'll need to step into the code with the Visual Studio debugger and
see what object is null (Nothing). I'd suspect either chkEbay is
Nothing or the reference returned by FindControl is Nothing.

One other tip: you can use FindControl on the Item object instead of a
cell (e.Item.FindControl(...)), this makes the code a bit more robust
if you ever change column ordering.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 17 Mar 2005 14:59:02 -0800, "Rudy"
<Rudy@.discussions.microsoft.com> wrote:

>Hello All!
>I get this error at this line
>Line 368: Len(e.Item.Cells(5).Text) - 1)
>Line 369: txtQty.Text = e.Item.Cells(5).Text
>****Line 370: chkEbay.Checked =
>CType(e.Item.Cells(6).FindControl("chkEbay"), _****
>Line 371: CheckBox).Checked
>Line 372: chkSold.Checked =
>CType(e.Item.Cells(7).FindControl("chkSold"), _
>It comes up when I hit the Edit button on my data grid, here is my code for
>that sub. Any thoughts?
> Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
>System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
>grdUinv.ItemCommand
> If e.Item.ItemType = ListItemType.Pager Or _
>e.Item.ItemType = ListItemType.Header Then Exit Sub
> grdUinv.EditItemIndex = -1
>
> Dim btn As Button = CType(e.CommandSource, Button)
> If btn.Text = "Edit" Then
> txbProductID.Text = e.Item.Cells(0).Text
> txtProdName.Text = e.Item.Cells(1).Text
> txtModNum.Text = e.Item.Cells(2).Text
> txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text, _
> Len(e.Item.Cells(4).Text) - 1)
> txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text, _
> Len(e.Item.Cells(5).Text) - 1)
> txtQty.Text = e.Item.Cells(5).Text
> chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"), _
> CheckBox).Checked
> chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"), _
> CheckBox).Checked
> pnlAdd.Visible = True
> Else
> ' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToSt ring)
> End If
> btnSave.CommandArgument = ""
> End Sub
>TIA!!!
>Rudy
Thanks fot the tip Scott. Can you please give a quick example of the Find
CFontrol on the item object.

You were right, refrence was nothing.

Have a great weekend!

Rudy

"Scott Allen" wrote:

> Hi Rudy:
> You'll need to step into the code with the Visual Studio debugger and
> see what object is null (Nothing). I'd suspect either chkEbay is
> Nothing or the reference returned by FindControl is Nothing.
> One other tip: you can use FindControl on the Item object instead of a
> cell (e.Item.FindControl(...)), this makes the code a bit more robust
> if you ever change column ordering.
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
> On Thu, 17 Mar 2005 14:59:02 -0800, "Rudy"
> <Rudy@.discussions.microsoft.com> wrote:
> >Hello All!
> >I get this error at this line
> >Line 368: Len(e.Item.Cells(5).Text) - 1)
> >Line 369: txtQty.Text = e.Item.Cells(5).Text
> >****Line 370: chkEbay.Checked =
> >CType(e.Item.Cells(6).FindControl("chkEbay"), _****
> >Line 371: CheckBox).Checked
> >Line 372: chkSold.Checked =
> >CType(e.Item.Cells(7).FindControl("chkSold"), _
> >It comes up when I hit the Edit button on my data grid, here is my code for
> >that sub. Any thoughts?
> > Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
> >System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
> >grdUinv.ItemCommand
> > If e.Item.ItemType = ListItemType.Pager Or _
> >e.Item.ItemType = ListItemType.Header Then Exit Sub
> > grdUinv.EditItemIndex = -1
> > Dim btn As Button = CType(e.CommandSource, Button)
> > If btn.Text = "Edit" Then
> > txbProductID.Text = e.Item.Cells(0).Text
> > txtProdName.Text = e.Item.Cells(1).Text
> > txtModNum.Text = e.Item.Cells(2).Text
> > txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text, _
> > Len(e.Item.Cells(4).Text) - 1)
> > txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text, _
> > Len(e.Item.Cells(5).Text) - 1)
> > txtQty.Text = e.Item.Cells(5).Text
> > chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"), _
> > CheckBox).Checked
> > chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"), _
> > CheckBox).Checked
> > pnlAdd.Visible = True
> > Else
> > ' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToSt ring)
> > End If
> > btnSave.CommandArgument = ""
> > End Sub
> >TIA!!!
> >Rudy
>
Hi Rudy:

I have some tips here:
http://odetocode.com/Articles/116.aspx

The code is in C# but the principles remain the same.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 18 Mar 2005 10:05:05 -0800, "Rudy"
<Rudy@.discussions.microsoft.com> wrote:

>Thanks fot the tip Scott. Can you please give a quick example of the Find
>CFontrol on the item object.
>You were right, refrence was nothing.
>Have a great weekend!
>Rudy
>"Scott Allen" wrote:
>> Hi Rudy:
>>
>> You'll need to step into the code with the Visual Studio debugger and
>> see what object is null (Nothing). I'd suspect either chkEbay is
>> Nothing or the reference returned by FindControl is Nothing.
>>
>> One other tip: you can use FindControl on the Item object instead of a
>> cell (e.Item.FindControl(...)), this makes the code a bit more robust
>> if you ever change column ordering.
>>
>> --
>> Scott
>> http://www.OdeToCode.com/blogs/scott/
>>
>> On Thu, 17 Mar 2005 14:59:02 -0800, "Rudy"
>> <Rudy@.discussions.microsoft.com> wrote:
>>
>> >Hello All!
>>> >I get this error at this line
>> >Line 368: Len(e.Item.Cells(5).Text) - 1)
>> >Line 369: txtQty.Text = e.Item.Cells(5).Text
>> >****Line 370: chkEbay.Checked =
>> >CType(e.Item.Cells(6).FindControl("chkEbay"), _****
>> >Line 371: CheckBox).Checked
>> >Line 372: chkSold.Checked =
>> >CType(e.Item.Cells(7).FindControl("chkSold"), _
>>> >It comes up when I hit the Edit button on my data grid, here is my code for
>> >that sub. Any thoughts?
>>> > Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
>> >System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
>> >grdUinv.ItemCommand
>>> > If e.Item.ItemType = ListItemType.Pager Or _
>> >e.Item.ItemType = ListItemType.Header Then Exit Sub
>> > grdUinv.EditItemIndex = -1
>>>> > Dim btn As Button = CType(e.CommandSource, Button)
>> > If btn.Text = "Edit" Then
>> > txbProductID.Text = e.Item.Cells(0).Text
>> > txtProdName.Text = e.Item.Cells(1).Text
>> > txtModNum.Text = e.Item.Cells(2).Text
>> > txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text, _
>> > Len(e.Item.Cells(4).Text) - 1)
>> > txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text, _
>> > Len(e.Item.Cells(5).Text) - 1)
>> > txtQty.Text = e.Item.Cells(5).Text
>> > chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"), _
>> > CheckBox).Checked
>> > chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"), _
>> > CheckBox).Checked
>> > pnlAdd.Visible = True
>> > Else
>> > ' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToSt ring)
>>> > End If
>> > btnSave.CommandArgument = ""
>> > End Sub
>>> >TIA!!!
>>> >Rudy
>>>
>

Object reference not set to an instance of an object

Hello All!
I get this error at this line
Line 368: Len(e.Item.Cells(5).Text) - 1)
Line 369: txtQty.Text = e.Item.Cells(5).Text
****Line 370: chkEbay.Checked =
CType(e.Item.Cells(6).FindControl("chkEbay"), _****
Line 371: CheckBox).Checked
Line 372: chkSold.Checked =
CType(e.Item.Cells(7).FindControl("chkSold"), _
It comes up when I hit the Edit button on my data grid, here is my code for
that sub. Any thoughts?
Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grdUinv.ItemCommand
If e.Item.ItemType = ListItemType.Pager Or _
e.Item.ItemType = ListItemType.Header Then Exit Sub
grdUinv.EditItemIndex = -1
Dim btn As Button = CType(e.CommandSource, Button)
If btn.Text = "Edit" Then
txbProductID.Text = e.Item.Cells(0).Text
txtProdName.Text = e.Item.Cells(1).Text
txtModNum.Text = e.Item.Cells(2).Text
txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text, _
Len(e.Item.Cells(4).Text) - 1)
txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text, _
Len(e.Item.Cells(5).Text) - 1)
txtQty.Text = e.Item.Cells(5).Text
chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"), _
CheckBox).Checked
chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"), _
CheckBox).Checked
pnlAdd.Visible = True
Else
' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToString)
End If
btnSave.CommandArgument = ""
End Sub
TIA!!!
RudyHi Rudy:
You'll need to step into the code with the Visual Studio debugger and
see what object is null (Nothing). I'd suspect either chkEbay is
Nothing or the reference returned by FindControl is Nothing.
One other tip: you can use FindControl on the Item object instead of a
cell (e.Item.FindControl(...)), this makes the code a bit more robust
if you ever change column ordering.
Scott
http://www.OdeToCode.com/blogs/scott/
On Thu, 17 Mar 2005 14:59:02 -0800, "Rudy"
<Rudy@.discussions.microsoft.com> wrote:

>Hello All!
>I get this error at this line
>Line 368: Len(e.Item.Cells(5).Text) - 1)
>Line 369: txtQty.Text = e.Item.Cells(5).Text
>****Line 370: chkEbay.Checked =
>CType(e.Item.Cells(6).FindControl("chkEbay"), _****
>Line 371: CheckBox).Checked
>Line 372: chkSold.Checked =
>CType(e.Item.Cells(7).FindControl("chkSold"), _
>It comes up when I hit the Edit button on my data grid, here is my code for
>that sub. Any thoughts?
> Private Sub grdUinv_ItemCommand(ByVal source As Object, ByVal e As
>System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
>grdUinv.ItemCommand
> If e.Item.ItemType = ListItemType.Pager Or _
>e.Item.ItemType = ListItemType.Header Then Exit Sub
> grdUinv.EditItemIndex = -1
>
> Dim btn As Button = CType(e.CommandSource, Button)
> If btn.Text = "Edit" Then
> txbProductID.Text = e.Item.Cells(0).Text
> txtProdName.Text = e.Item.Cells(1).Text
> txtModNum.Text = e.Item.Cells(2).Text
> txtSrp.Text = Microsoft.VisualBasic.Right(e.Item.Cells(3).Text,
_
> Len(e.Item.Cells(4).Text) - 1)
> txtCost.Text = Microsoft.VisualBasic.Right(e.Item.Cells(4).Text
, _
> Len(e.Item.Cells(5).Text) - 1)
> txtQty.Text = e.Item.Cells(5).Text
> chkEbay.Checked = CType(e.Item.Cells(6).FindControl("chkEbay"),
_
> CheckBox).Checked
> chkSold.Checked = CType(e.Item.Cells(7).FindControl("chkSold"),
_
> CheckBox).Checked
> pnlAdd.Visible = True
> Else
> ' DeleteItem(grdUinv.DataKeys(e.Item.ItemIndex).ToString)
> End If
> btnSave.CommandArgument = ""
> End Sub
>TIA!!!
>Rudy
>
Thanks fot the tip Scott. Can you please give a quick example of the Find
CFontrol on the item object.
You were right, refrence was nothing.
Have a great wend!
Rudy
"Scott Allen" wrote:

> Hi Rudy:
> You'll need to step into the code with the Visual Studio debugger and
> see what object is null (Nothing). I'd suspect either chkEbay is
> Nothing or the reference returned by FindControl is Nothing.
> One other tip: you can use FindControl on the Item object instead of a
> cell (e.Item.FindControl(...)), this makes the code a bit more robust
> if you ever change column ordering.
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
> On Thu, 17 Mar 2005 14:59:02 -0800, "Rudy"
> <Rudy@.discussions.microsoft.com> wrote:
>
>
Hi Rudy:
I have some tips here:
http://odetocode.com/Articles/116.aspx
The code is in C# but the principles remain the same.
HTH,
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 18 Mar 2005 10:05:05 -0800, "Rudy"
<Rudy@.discussions.microsoft.com> wrote:
>Thanks fot the tip Scott. Can you please give a quick example of the Find
>CFontrol on the item object.
>You were right, refrence was nothing.
>Have a great wend!
>Rudy
>"Scott Allen" wrote:
>

Thursday, March 22, 2012

Object reference not set to an instance of an object.

I get the error: Object reference not set to an instance of an object

With this code:

Dim test3 As New TextBox
test3 = CType(e.Item.FindControl("name"), TextBox)
Dim name As String = test3.Text

The specific line is:

Dim name As String = test3.Text

So, what do I need to do to fix that?

Thanks.Because e.Item.FindControl() does not find a control named as "name", hence
next line of code gives you that error.

You need to figure out why there is no TextBox, called "name" found.

"Jim in Arizona" <tiltowait@.hotmail.comwrote in message
news:ePOMLuz1GHA.4300@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I get the error: Object reference not set to an instance of an object
>
With this code:
>
Dim test3 As New TextBox
test3 = CType(e.Item.FindControl("name"), TextBox)
Dim name As String = test3.Text
>
The specific line is:
>
Dim name As String = test3.Text
>
So, what do I need to do to fix that?
>
Thanks.


Yep. That's it. Thanks. Now I have another question to post regarding
this whole mess, which I bet no one will have an answer for.

Thanks Norman.

Norman Yuan wrote:

Quote:

Originally Posted by

Because e.Item.FindControl() does not find a control named as "name", hence
next line of code gives you that error.
>
You need to figure out why there is no TextBox, called "name" found.
>
"Jim in Arizona" <tiltowait@.hotmail.comwrote in message
news:ePOMLuz1GHA.4300@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I get the error: Object reference not set to an instance of an object
>>
>With this code:
>>
> Dim test3 As New TextBox
> test3 = CType(e.Item.FindControl("name"), TextBox)
> Dim name As String = test3.Text
>>
>The specific line is:
>>
> Dim name As String = test3.Text
>>
>So, what do I need to do to fix that?
>>
>Thanks.


>
>

Object reference not set to an instance of an object.

Dim sTextBoxName As String =
e.Item.Cells(0).FindControl("tbtempDateF").ClientID() ******Error Here

CType(e.Item.FindControl("lnkCalendarF"), HyperLink).NavigateUrl =
"javascript:calendar_window=window.open('calendar.a spx?formname=Form1." &
sTextBoxName &
"','Pick_A_Date','width=154,height=210');calendar_w indow.focus();"

--
I am using the free version of SPAMfighter for private users.
It has removed 0 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!Clearly, something in that chain is coming up with a null reference. My
guess is that it cannot find the control you are telling it to via
FindControl.

"Fetty" <dfetrow410@.hotmail.com> wrote in message
news:%234MlSpxVFHA.3488@.tk2msftngp13.phx.gbl...
> Dim sTextBoxName As String =
> e.Item.Cells(0).FindControl("tbtempDateF").ClientID() ******Error Here
> CType(e.Item.FindControl("lnkCalendarF"), HyperLink).NavigateUrl =
> "javascript:calendar_window=window.open('calendar.a spx?formname=Form1." &
> sTextBoxName &
> "','Pick_A_Date','width=154,height=210');calendar_w indow.focus();"
>
> --
> I am using the free version of SPAMfighter for private users.
> It has removed 0 spam emails to date.
> Paying users do not have this message in their emails.
> Try www.SPAMfighter.com for free now!
probably..
Solved it?
Patrick

"Marina" wrote:

> Clearly, something in that chain is coming up with a null reference. My
> guess is that it cannot find the control you are telling it to via
> FindControl.
> "Fetty" <dfetrow410@.hotmail.com> wrote in message
> news:%234MlSpxVFHA.3488@.tk2msftngp13.phx.gbl...
> > Dim sTextBoxName As String =
> > e.Item.Cells(0).FindControl("tbtempDateF").ClientID() ******Error Here
> > CType(e.Item.FindControl("lnkCalendarF"), HyperLink).NavigateUrl =
> > "javascript:calendar_window=window.open('calendar.a spx?formname=Form1." &
> > sTextBoxName &
> > "','Pick_A_Date','width=154,height=210');calendar_w indow.focus();"
> > --
> > I am using the free version of SPAMfighter for private users.
> > It has removed 0 spam emails to date.
> > Paying users do not have this message in their emails.
> > Try www.SPAMfighter.com for free now!
>

Friday, March 16, 2012

Object reference not set to an instance of an object.

Dim sTextBoxName As String =
e.Item.Cells(0).FindControl("tbtempDateF").ClientID() ******Error Here
CType(e.Item.FindControl("lnkCalendarF"), HyperLink).NavigateUrl =
"java script:calendar_window=window.open('calendar.aspx?formname=Form1." &
sTextBoxName &
" ','Pick_A_Date','width=154,height=210');
calendar_window.focus();"
I am using the free version of SPAMfighter for private users.
It has removed 0 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!Clearly, something in that chain is coming up with a null reference. My
guess is that it cannot find the control you are telling it to via
FindControl.
"Fetty" <dfetrow410@.hotmail.com> wrote in message
news:%234MlSpxVFHA.3488@.tk2msftngp13.phx.gbl...
> Dim sTextBoxName As String =
> e.Item.Cells(0).FindControl("tbtempDateF").ClientID() ******Error Here
> CType(e.Item.FindControl("lnkCalendarF"), HyperLink).NavigateUrl =
> "java script:calendar_window=window.open('calendar.aspx?formname=Form1." &
> sTextBoxName &
> " ','Pick_A_Date','width=154,height=210');
calendar_window.focus();"
>
> --
> I am using the free version of SPAMfighter for private users.
> It has removed 0 spam emails to date.
> Paying users do not have this message in their emails.
> Try www.SPAMfighter.com for free now!
>
probably..
Solved it?
Patrick
"Marina" wrote:

> Clearly, something in that chain is coming up with a null reference. My
> guess is that it cannot find the control you are telling it to via
> FindControl.
> "Fetty" <dfetrow410@.hotmail.com> wrote in message
> news:%234MlSpxVFHA.3488@.tk2msftngp13.phx.gbl...
>
>