Cannot access data row in Repeater ItemCommand event

G

Guest

Hello,

I am trying to determine the proper way to access the underlying data row
for a Repeater item in the ItemCommand event. In the page load event, I bind
the Repeater data source to a SqlDataReader. I check for !IsPostBack so the
data binding only happens the first time.

In the ItemCommand event, e.Item.DataItem is unassigned. Any suggestions?
Thanks!
 
J

John Saunders

Joel Daniels said:
Hello,

I am trying to determine the proper way to access the underlying data row
for a Repeater item in the ItemCommand event. In the page load event, I
bind
the Repeater data source to a SqlDataReader. I check for !IsPostBack so
the
data binding only happens the first time.

In the ItemCommand event, e.Item.DataItem is unassigned. Any suggestions?

It's supposed to be unassigned. What would it be set to? There's no data on
post back!

If you supply the DataKey property property to the DataGrid when you
DataBind it, then you can use the ItemIndex of the RepeaterItem to index
into the DataKeys property of the DataGrid. Given the primary key of the
DataRow which originally loaded that Repeater item, you can load it again.

John Saunders
 
G

Guest

I'm working with a repeater, not a datagrid. There is no DataKey property
that I can see.

Since data binding only happens one time, I may need to either store a data
value in a hidden field on the item template or else use the value for a
CommandArgument.
 
G

Guest

I'm working with a repeater, not a datagrid. There is no DataKey property
that I can see.

Since data binding only happens one time, I may need to either store a data
value in a hidden field on the item template or else use the value for a
CommandArgument.
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top