how I can to access my Repeater DataItem when a fire button command? I can see that DataItem return null.
There is some possibility?
how I can to access my Repeater DataItem when a fire button command? I can see that DataItem return null.
There is some possibility?
set the id of the object in the CommandArgument of the button. then in the button command event you can access the id from e.CommandArgument. you can then query the domain/db for the data.
You should make sure it's not a header row, where you see that DataItem
is null
.
You can do it by encapsulating your code with if
statement simply checking if DataItem
is not null
or if it's of a specified type you use to assign data to that Repeater
.
Alternatively you can check ListItemType of an item as described here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx or here: ASP.Net repeater item.DataItem is null.
You should then be able to access data associated with each of the items in ItemDataBound event by accessing e.Item.DataItem
object.
If you want to access data assigned to the repeater from another event invoked from control bound (i.e. button click like you mentioned) you can use CommandArgument
and assign appropriate value to it for each of the items and handle ButtonCommand
.