I have a object datasource for a telerik listview and on the onitemcreated method I want to be able to pul开发者_StackOverflow中文版l out that current object that it is on. can anyone help me? Thanks
You cannot access the data object in OnItemCreated
because that occurs before any data binding occurs. Instead, you should do you processing in OnItemDataBound
. You can use logic like this:
var listDataItem = e.Item as RadListViewDataItem;
if (listDataItem != null)
{
var theData = listDataItem.DataItem;
//...
}
Telerik has a page in their documentation specifically addressing the differences between the ItemCreated
and ItemDataBound
events. Here is a snippet of that:
ItemCreated is fired before the item is data-bound. Thus no data is still in the listview item or the controls nested inside it. In ItemDataBound all is available.
精彩评论