|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
e.Item.DataItemHello,
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? 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? 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----- you try to refer to >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 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? > > >. > 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? >> >> >>. >> 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? The last line is failing. How I can resolve that?
>-----Original Message----- to use drv as if it >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 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? > > >. > 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----- to use drv as if it >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 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? > > >. > 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? >. > 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? >>. >> That's what you think.
>-----Original Message----- problem. Because of >Well, technically it's not the DataSource that is the >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? >>>. >>> > > >. >
Default Paging
Background of datagrid Inserting Text before the Numberic Page numbers in paging Changing paging look moving data from a page to an other page TemplateColumn with CheckBox DataBind in C# recursive relation in datagrid dataView Need some hints before starting to change a page Disable button in datagird on condition |
|||||||||||||||||||||||