471,339 Members | 1,231 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Object reference not set to an instance of an object :(

UGH
I am looping the grid rows to set the values in the dropdownlists. I keep
getting a run time error "Object reference not set to an instance of an
object." The error occurs on line where it says liitem=
dp.items.findbyvalues(st). I am not sure what I am doing wrong. I included
my codes so someone can point out my mistake. Thanks.
Private Sub reset_values()
Dim i As Long
Dim dp As DropDownList

Dim intIndex As Int32
Dim liItem As ListItem

Dim st As String

For i = 0 To grdAct.Items.Count - 1
dp = CType(grdAct.FindControl("dpl"), DropDownList)
st = grdAct.Items(i).Cells(5).Text

liItem = dp.Items.FindByValue(st) ( error occurs on this line )
intIndex = dp.Items.IndexOf(liItem)
dp.SelectedIndex = intIndex
Next

End Sub
Jul 21 '05 #1
3 3301

I think the following code will solve your issue. Why st is returning
"nothing" I can not help you with.

Private Sub reset_values()
Dim i As Long
Dim dp As DropDownList

Dim intIndex As Int32
Dim liItem As ListItem

Dim st As String

For i = 0 To grdAct.Items.Count - 1
dp = CType(grdAct.FindControl("dpl"), DropDownList)
st = grdAct.Items(i).Cells(5).Text

if not st is nothing then
'st is value, go ahead and do it
liItem = dp.Items.FindByValue(st) ( error occurs on this
line )
intIndex = dp.Items.IndexOf(liItem)
dp.SelectedIndex = intIndex
else
'For some reason grdAct.Items(i).Cells(5).Text
'returns nothing
end if
Next
End Sub

"UGH" <no****@noSPam.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...I am looping the grid rows to set the values in the dropdownlists. I keep
getting a run time error "Object reference not set to an instance of an
object." The error occurs on line where it says liitem=
dp.items.findbyvalues(st). I am not sure what I am doing wrong. I included
my codes so someone can point out my mistake. Thanks.
Private Sub reset_values()
Dim i As Long
Dim dp As DropDownList

Dim intIndex As Int32
Dim liItem As ListItem

Dim st As String

For i = 0 To grdAct.Items.Count - 1
dp = CType(grdAct.FindControl("dpl"), DropDownList)
st = grdAct.Items(i).Cells(5).Text

liItem = dp.Items.FindByValue(st) ( error occurs on this line )
intIndex = dp.Items.IndexOf(liItem)
dp.SelectedIndex = intIndex
Next

End Sub

Jul 21 '05 #2
UGH
That did not work. The st is never empy. I think somthig is wrong with dp
variable.

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...

I think the following code will solve your issue. Why st is returning
"nothing" I can not help you with.

Private Sub reset_values()
Dim i As Long
Dim dp As DropDownList

Dim intIndex As Int32
Dim liItem As ListItem

Dim st As String

For i = 0 To grdAct.Items.Count - 1
dp = CType(grdAct.FindControl("dpl"), DropDownList)
st = grdAct.Items(i).Cells(5).Text

if not st is nothing then
'st is value, go ahead and do it
liItem = dp.Items.FindByValue(st) ( error occurs on this
line )
intIndex = dp.Items.IndexOf(liItem)
dp.SelectedIndex = intIndex
else
'For some reason grdAct.Items(i).Cells(5).Text
'returns nothing
end if
Next
End Sub

"UGH" <no****@noSPam.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
I am looping the grid rows to set the values in the dropdownlists. I keep
getting a run time error "Object reference not set to an instance of an
object." The error occurs on line where it says liitem=
dp.items.findbyvalues(st). I am not sure what I am doing wrong. I included
my codes so someone can point out my mistake. Thanks.
Private Sub reset_values()
Dim i As Long
Dim dp As DropDownList

Dim intIndex As Int32
Dim liItem As ListItem

Dim st As String

For i = 0 To grdAct.Items.Count - 1
dp = CType(grdAct.FindControl("dpl"), DropDownList)
st = grdAct.Items(i).Cells(5).Text

liItem = dp.Items.FindByValue(st) ( error occurs on this
line )
intIndex = dp.Items.IndexOf(liItem)
dp.SelectedIndex = intIndex
Next

End Sub


Jul 21 '05 #3
You should use similar code to what Chris posted to check the dp
variable as well.

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Daniel | last post: by
15 posts views Thread by Carlos Lozano | last post: by
4 posts views Thread by Luke Matuszewski | last post: by
12 posts views Thread by Andrew Poulos | last post: by
6 posts views Thread by Shailen Sukul | last post: by
14 posts views Thread by Philipp Reif | last post: by
reply views Thread by rosydwin | last post: by

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.