Accessing the current DataItem in the ItemCommand event

N

Nathan Sokalski

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

Eliyahu Goldin

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top