Professional Web Applications Themes

e.Item.DataItem - ASP.NET Data Grid Control

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

  1. #1

    Default e.Item.DataItem

    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?
    anonymous Guest

  2. #2

    Default Re: e.Item.DataItem

    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" <anonymousdiscussions.microsoft.com> wrote in message
    news:351c01c51f3f$a17b24d0$a601280aphx.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?

    Arthur Dent Guest

  3. #3

    Default Re: e.Item.DataItem

    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.


    "anonymous" <anonymousdiscussions.microsoft.com> wrote in message
    news:351c01c51f3f$a17b24d0$a601280aphx.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?

    Scott M. Guest

  4. #4

    Default Re: e.Item.DataItem

    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.
    >
    >
    >"anonymous" <anonymousdiscussions.microsoft.com> wrote
    in message
    >news:351c01c51f3f$a17b24d0$a601280aphx.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?
    >
    >
    >.
    >
    anonymous Guest

  5. #5

    Default Re: e.Item.DataItem

    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" <anonymousdiscussions.microsoft.com> wrote
    in message
    >news:351c01c51f3f$a17b24d0$a601280aphx.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?
    >
    >
    >.
    >
    Anonymous Guest

  6. #6

    Default Re: e.Item.DataItem

    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: [url]http://msdn.microsoft.com/library/en-[/url]
    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
    >was an array when, in fact, it isn't.
    >
    >
    >"anonymous" <anonymousdiscussions.microsoft.com> wrote
    in message
    >news:351c01c51f3f$a17b24d0$a601280aphx.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?
    >
    >
    >.
    >
    anonymous Guest

  7. #7

    Default Re: e.Item.DataItem

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


    "Anonymous" <anonymousdiscussions.microsoft.com> wrote in message
    news:20f401c51f43$438c5f70$a501280aphx.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" <anonymousdiscussions.microsoft.com> wrote
    > in message
    >>news:351c01c51f3f$a17b24d0$a601280aphx.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?
    >>
    >>
    >>.
    >>

    Scott M. Guest

  8. #8

    Default e.Item.DataItem

    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
    [email]elton_wanghotmail.com[/email]
    >-----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?
    >.
    >
    Elton Wang Guest

  9. #9

    Default Re: e.Item.DataItem

    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.




    "Elton Wang" <anonymousdiscussions.microsoft.com> wrote in message
    news:226501c51f54$403a8ca0$a501280aphx.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
    > [email]elton_wanghotmail.com[/email]
    >
    >>-----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?
    >>.
    >>

    Scott M. Guest

  10. #10

    Default Re: e.Item.DataItem

    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.
    >
    >
    >
    >
    >"Elton Wang" <anonymousdiscussions.microsoft.com> wrote
    in message
    >news:226501c51f54$403a8ca0$a501280aphx.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
    >> [email]elton_wanghotmail.com[/email]
    >>
    >>>-----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?
    >>>.
    >>>
    >
    >
    >.
    >
    Elton Wang Guest

  11. #11

    Default e.item.dataitem

    hey,

    I have created a datalist and added some data into it,
    via a dataset. Each row contains an +/- button, which has
    a commandname associated to it. Now whenever somebody
    presses the +/- button, I need to get the data from that
    cell. For that I am using the ItemCommand, but
    e.item.dataitem is always empty. How I am supposed to get
    the data?

    Any help is very appreciated.
    Thanks
    anonymous Guest

  12. #12

    Default Re: e.item.dataitem

    AFAIK there will not be anything in dataItem when an event is posted.
    It is used inside the _ItemDataBound events while the display is
    being built.

    The event artgs has an ItemIndex property that indicated which row was
    clicked. You can use this to read the proper key and get the unique
    identifier :

    int rowNum = e.Item.ItemIndex;
    string pKey = dgrid.DataKeys[ rowNum ].ToString();

    - Andrew Backer

    Andrew Backer Guest

Similar Threads

  1. how to use a fuction in dataitem ?
    By Kylin in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: June 2nd, 10:20 PM
  2. DataGridItem.DataItem property?
    By Joel Lyons in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: October 26th, 08:30 PM
  3. Replies: 6
    Last Post: January 17th, 07:46 PM
  4. Is e.Item.DataItem (DataRow) available on postback??
    By David Adams in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: October 13th, 06:47 PM
  5. How to check if CType(e.Item.DataItem, DataRowView) is DBNULL
    By Rob Wire in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: July 30th, 04:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139