Object reference not set to an instance of an object.

S

SK

Hello,

I have a datagrid, which contains another nested
datagrid as a user control. The nested dg is popultated
when the user presses the "+" button in one row for the
main grid. I have a implemented an ItemCommand event which
looks like this:

Select Case e.CommandName
Case "Expand" ' user pressed the + button
' get a reference to the placeholer
Dim ExpandedContent As PlaceHolder = e.Item.Cells
(dgMain.Columns.Count - 1).FindControl("ExpandedContent")
Dim btnExpand As ImageButton = e.Item.Cells(0).FindControl
("btnExpand")
If btnExpand.ImageUrl = "~/Images/Plus.gif" Then
Dim ctrl As UserControl
ctrl = e.Item.Cells(dgMain.Columns.Count -
1).FindControl("GetStylePerStore1")
Dim objGetStylePerStore As GetStylePerStore =
DirectCast(ctrl, GetStylePerStore)
objGetStylePerStore.StartDate = ViewState("StartDate")
....
....

Now the probklem is that from time to time I get the error
Object reference not set to an instance of an object in
the last line of the above code. When I press f5 then it
works again sometimes, but sometimes it doesnt. I am
confused why I am getting this error. Can somebody help?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top