Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing the current DataItem in the ItemCommand event

Reply
Thread Tools

Accessing the current DataItem in the ItemCommand event

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      05-28-2007
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.It em.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.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-28-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.It em.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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net Building Controls 1 09-13-2007 04:45 PM
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net Web Controls 1 09-13-2007 04:45 PM
Retrieving the DataItem property in DataList's ItemCommand or SelectedIndexChanged event Nathan Sokalski ASP .Net 1 09-13-2007 04:45 PM
Event Bubbling and the ItemCommand Event Nathan Sokalski ASP .Net 0 05-29-2006 07:16 AM
Event Bubbling and the ItemCommand Event Nathan Sokalski ASP .Net Datagrid Control 0 05-29-2006 07:16 AM



Advertisments