467,915 Members | 1,625 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Accessing the current DataItem in the ItemCommand event

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
nj********@hotmail.com
http://www.nathansokalski.com/
May 28 '07 #1
  • viewed: 6955
Share:
1 Reply
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" <nj********@hotmail.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/


May 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steven | last post: by
reply views Thread by Solomon Shaffer | last post: by
2 posts views Thread by Deepesh | last post: by
reply views Thread by Nathan Sokalski | last post: by
4 posts views Thread by John Kotuby | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.