e.Item.DataItem

A

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?
 
A

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.
 
S

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.
 
A

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
was an array when, in fact, it isn't.





.
 
A

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), "%", "%","%")
 
A

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
 
S

Scott M.

But headers and footers and pagers are items, so you must test
e.Item.DataItem as Arthur suggests.
 
E

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
(e-mail address removed)
 
S

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.
 
E

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
have bound itself to it unless you call DataBind.







.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top