Accessing the current DataItem in the ItemCommand event

Discussion in 'ASP .Net' started by Nathan Sokalski, May 28, 2007.

  1. I need to access one of the columns from the current DataItem in the
    ItemCommand event, which I call using EventBubbling with a DataList and
    Button control. The code I tried to use to access the current DataItem is
    the following:

    CStr(CType(e.Item.DataItem, DataRowView)("id"))


    However, after some experimenting, I found out that e.Item.DataItem is
    Nothing in the ItemCommand event by using the following statement:

    System.Diagnostics.Debug.WriteLine("IsNothing(e.Item.DataItem): " &
    CStr(IsNothing(e.Item.DataItem)))


    This statement ouput the value "True". Does anybody have any ideas as to
    what might be a good way to get the column values that were used for the
    current Item? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, May 28, 2007
    #1
    1. Advertising

  2. DataItem is available only in ItemDataBound event as it is the only time
    where the control items connect to their datasource. If you need the
    datasource field values in other places, you need to take a special care of
    it. You may consider including the values in the item template and hiding
    them with css style display:none. Then you can access them in postbacks.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Nathan Sokalski" <> wrote in message
    news:...
    > I need to access one of the columns from the current DataItem in the
    > ItemCommand event, which I call using EventBubbling with a DataList and
    > Button control. The code I tried to use to access the current DataItem is
    > the following:
    >
    > CStr(CType(e.Item.DataItem, DataRowView)("id"))
    >
    >
    > However, after some experimenting, I found out that e.Item.DataItem is
    > Nothing in the ItemCommand event by using the following statement:
    >
    > System.Diagnostics.Debug.WriteLine("IsNothing(e.Item.DataItem): " &
    > CStr(IsNothing(e.Item.DataItem)))
    >
    >
    > This statement ouput the value "True". Does anybody have any ideas as to
    > what might be a good way to get the column values that were used for the
    > current Item? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
     
    Eliyahu Goldin, May 28, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    410
    Nathan Sokalski
    May 29, 2006
  2. Nathan Sokalski
    Replies:
    1
    Views:
    495
    Teemu Keiski
    Sep 13, 2007
  3. Nathan Sokalski
    Replies:
    1
    Views:
    1,017
    Teemu Keiski
    Sep 13, 2007
  4. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    148
    Nathan Sokalski
    May 29, 2006
  5. Nathan Sokalski
    Replies:
    1
    Views:
    228
    Teemu Keiski
    Sep 13, 2007
Loading...

Share This Page