Home All Groups Group Topic Archive Search About
Author
2 Mar 2005 3:51 PM
anonymous
Hello,

    I need to pass e.item.dataitem to my user control,
from the ItemCommand method. But each time I do this, I
get the following error:

Object variable or With block variable not set.

It happens when I access the data. Its something like this:

Private Sub Dg_ItemCommand...
Dim drv As Object = e.Item.DataItem
  objUC.Binddata(drv(1), drv(2), "%", "%","%")
End Sub

Any idea?

Author
2 Mar 2005 4:01 PM
Arthur Dent
make sure youre only passing the item if
e.Item.ItemType = Item OrElse e.Item.ItemType = AlternatingItem.
Those are the only types for which DataItem is valid. If you try to refer to
it on a type Header, Pager, Footer, youll get that error.


Show quoteHide quote
"anonymous" <anonym***@discussions.microsoft.com> wrote in message
news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
> Hello,
>
>    I need to pass e.item.dataitem to my user control,
> from the ItemCommand method. But each time I do this, I
> get the following error:
>
> Object variable or With block variable not set.
>
> It happens when I access the data. Its something like this:
>
> Private Sub Dg_ItemCommand...
> Dim drv As Object = e.Item.DataItem
>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
> End Sub
>
> Any idea?
Author
2 Mar 2005 4:17 PM
Anonymous
As said I am using the code in the ItemCommand method. I
trued to put the code inside the item type, but still get
the same error. The error occurs at this line:

objUC.Binddata(drv(1), drv(2), "%", "%","%")


>-----Original Message-----
>make sure youre only passing the item if
>e.Item.ItemType = Item OrElse e.Item.ItemType =
AlternatingItem.
>Those are the only types for which DataItem is valid. If
you try to refer to
Show quoteHide quote
>it on a type Header, Pager, Footer, youll get that error.
>
>
>"anonymous" <anonym***@discussions.microsoft.com> wrote
in message
>news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
>> Hello,
>>
>>    I need to pass e.item.dataitem to my user control,
>> from the ItemCommand method. But each time I do this, I
>> get the following error:
>>
>> Object variable or With block variable not set.
>>
>> It happens when I access the data. Its something like
this:
>>
>> Private Sub Dg_ItemCommand...
>> Dim drv As Object = e.Item.DataItem
>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>> End Sub
>>
>> Any idea?
>
>
>.
>
Author
2 Mar 2005 5:49 PM
Scott M.
But headers and footers and pagers are items, so you must test
e.Item.DataItem as Arthur suggests.


Show quoteHide quote
"Anonymous" <anonym***@discussions.microsoft.com> wrote in message
news:20f401c51f43$438c5f70$a501280a@phx.gbl...
> As said I am using the code in the ItemCommand method. I
> trued to put the code inside the item type, but still get
> the same error. The error occurs at this line:
>
> objUC.Binddata(drv(1), drv(2), "%", "%","%")
>
>
>>-----Original Message-----
>>make sure youre only passing the item if
>>e.Item.ItemType = Item OrElse e.Item.ItemType =
> AlternatingItem.
>>Those are the only types for which DataItem is valid. If
> you try to refer to
>>it on a type Header, Pager, Footer, youll get that error.
>>
>>
>>"anonymous" <anonym***@discussions.microsoft.com> wrote
> in message
>>news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
>>> Hello,
>>>
>>>    I need to pass e.item.dataitem to my user control,
>>> from the ItemCommand method. But each time I do this, I
>>> get the following error:
>>>
>>> Object variable or With block variable not set.
>>>
>>> It happens when I access the data. Its something like
> this:
>>>
>>> Private Sub Dg_ItemCommand...
>>> Dim drv As Object = e.Item.DataItem
>>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>>> End Sub
>>>
>>> Any idea?
>>
>>
>>.
>>
Author
2 Mar 2005 4:05 PM
Scott M.
Which particular line is failing?  Is it:

Dim drv As Object = e.Item.DataItem

or is it:

objUC.Binddata(drv(1), drv(2), "%", "%","%")

My guess is that it is the last one where you are trying to use drv as if it
was an array when, in fact, it isn't.


Show quoteHide quote
"anonymous" <anonym***@discussions.microsoft.com> wrote in message
news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
> Hello,
>
>    I need to pass e.item.dataitem to my user control,
> from the ItemCommand method. But each time I do this, I
> get the following error:
>
> Object variable or With block variable not set.
>
> It happens when I access the data. Its something like this:
>
> Private Sub Dg_ItemCommand...
> Dim drv As Object = e.Item.DataItem
>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
> End Sub
>
> Any idea?
Author
2 Mar 2005 4:13 PM
anonymous
The last line is failing. How I can resolve that?

>-----Original Message-----
>Which particular line is failing?  Is it:
>
>Dim drv As Object = e.Item.DataItem
>
>or is it:
>
>objUC.Binddata(drv(1), drv(2), "%", "%","%")
>
>My guess is that it is the last one where you are trying
to use drv as if it
Show quoteHide quote
>was an array when, in fact, it isn't.
>
>
>"anonymous" <anonym***@discussions.microsoft.com> wrote
in message
>news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
>> Hello,
>>
>>    I need to pass e.item.dataitem to my user control,
>> from the ItemCommand method. But each time I do this, I
>> get the following error:
>>
>> Object variable or With block variable not set.
>>
>> It happens when I access the data. Its something like
this:
>>
>> Private Sub Dg_ItemCommand...
>> Dim drv As Object = e.Item.DataItem
>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>> End Sub
>>
>> Any idea?
>
>
>.
>
Author
2 Mar 2005 4:21 PM
anonymous
According to the MSDN doc, I can use it this way:

drv("CompanyName").ToString()

I tried this, but get the same error. Any help is really
really apprecaited.

MSDN: http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfSystemDataDataRowViewClassItemTopic2.asp
?frame=true

Thanks


>-----Original Message-----
>Which particular line is failing?  Is it:
>
>Dim drv As Object = e.Item.DataItem
>
>or is it:
>
>objUC.Binddata(drv(1), drv(2), "%", "%","%")
>
>My guess is that it is the last one where you are trying
to use drv as if it
Show quoteHide quote
>was an array when, in fact, it isn't.
>
>
>"anonymous" <anonym***@discussions.microsoft.com> wrote
in message
>news:351c01c51f3f$a17b24d0$a601280a@phx.gbl...
>> Hello,
>>
>>    I need to pass e.item.dataitem to my user control,
>> from the ItemCommand method. But each time I do this, I
>> get the following error:
>>
>> Object variable or With block variable not set.
>>
>> It happens when I access the data. Its something like
this:
>>
>> Private Sub Dg_ItemCommand...
>> Dim drv As Object = e.Item.DataItem
>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>> End Sub
>>
>> Any idea?
>
>
>.
>
Author
2 Mar 2005 6:18 PM
Elton Wang
Hi there,

Item.DataItem is from underlying data source of the
datagrid. Mostly it is used in ItemCreated event and
ItemDataBound events. Unless you re-bind datagrid's data
source,  when postback the datagrid loses its underlying
data source.

I suppose you can get data from the datagrid itself, like
e.Item.Cells(colIndex).Text 

HTH

Elton Wang
elton_w***@hotmail.com

Show quoteHide quote
>-----Original Message-----
>Hello,
>
>    I need to pass e.item.dataitem to my user control,
>from the ItemCommand method. But each time I do this, I
>get the following error:
>
>Object variable or With block variable not set.
>
>It happens when I access the data. Its something like
this:
>
>Private Sub Dg_ItemCommand...
>Dim drv As Object = e.Item.DataItem
>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>End Sub
>
>Any idea?
>.
>
Author
2 Mar 2005 7:27 PM
Scott M.
Well, technically it's not the DataSource that is the problem.  Because of
ViewState, the grid will remember what its data source is, it just won't
have bound itself to it unless you call DataBind.




Show quoteHide quote
"Elton Wang" <anonym***@discussions.microsoft.com> wrote in message
news:226501c51f54$403a8ca0$a501280a@phx.gbl...
> Hi there,
>
> Item.DataItem is from underlying data source of the
> datagrid. Mostly it is used in ItemCreated event and
> ItemDataBound events. Unless you re-bind datagrid's data
> source,  when postback the datagrid loses its underlying
> data source.
>
> I suppose you can get data from the datagrid itself, like
> e.Item.Cells(colIndex).Text
>
> HTH
>
> Elton Wang
> elton_w***@hotmail.com
>
>>-----Original Message-----
>>Hello,
>>
>>    I need to pass e.item.dataitem to my user control,
>>from the ItemCommand method. But each time I do this, I
>>get the following error:
>>
>>Object variable or With block variable not set.
>>
>>It happens when I access the data. Its something like
> this:
>>
>>Private Sub Dg_ItemCommand...
>>Dim drv As Object = e.Item.DataItem
>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>>End Sub
>>
>>Any idea?
>>.
>>
Author
2 Mar 2005 8:18 PM
Elton Wang
That's what you think.

>-----Original Message-----
>Well, technically it's not the DataSource that is the
problem.  Because of
>ViewState, the grid will remember what its data source
is, it just won't
Show quoteHide quote
>have bound itself to it unless you call DataBind.
>
>
>
>
>"Elton Wang" <anonym***@discussions.microsoft.com> wrote
in message
>news:226501c51f54$403a8ca0$a501280a@phx.gbl...
>> Hi there,
>>
>> Item.DataItem is from underlying data source of the
>> datagrid. Mostly it is used in ItemCreated event and
>> ItemDataBound events. Unless you re-bind datagrid's data
>> source,  when postback the datagrid loses its underlying
>> data source.
>>
>> I suppose you can get data from the datagrid itself,
like
>> e.Item.Cells(colIndex).Text
>>
>> HTH
>>
>> Elton Wang
>> elton_w***@hotmail.com
>>
>>>-----Original Message-----
>>>Hello,
>>>
>>>    I need to pass e.item.dataitem to my user control,
>>>from the ItemCommand method. But each time I do this, I
>>>get the following error:
>>>
>>>Object variable or With block variable not set.
>>>
>>>It happens when I access the data. Its something like
>> this:
>>>
>>>Private Sub Dg_ItemCommand...
>>>Dim drv As Object = e.Item.DataItem
>>>  objUC.Binddata(drv(1), drv(2), "%", "%","%")
>>>End Sub
>>>
>>>Any idea?
>>>.
>>>
>
>
>.
>