This is a migrated thread and some comments may be shown as answers.

Access DataItem property of ListView databound Item

5 Answers 1200 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Roberto Yudice
Top achievements
Rank 1
Roberto Yudice asked on 10 May 2010, 04:57 PM
Hi, I need to perform some operations on the databound event of my RadListView however the event args do not include a data item unlike other args of the databound event, which event can I use to access the data item on databound?

5 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 11 May 2010, 02:29 PM
Hello Roberto,

Similar to ListView control you can access DataItem on ItemDataBound of RadListView by using following code:
1.protected void RadListView_ItemDataBound(object sender, RadListViewItemEventArgs e)
2.{
3.  if (e.Item is RadListViewDataItem)
4.  {
5.    var dataItem = ((RadListViewDataItem)e.Item).DataItem;
6.  }
7.}

I hope this helps.

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Anton Swanevelder
Top achievements
Rank 2
answered on 13 Nov 2011, 05:53 PM
Dear Telerik,

You guys rock and I love your controls. One of your strong points is that you keep as close to the microsoft controls as possible.

Is it possible that you can just expose the DataItem in the Item property instead of the complex cast .

The difference in code is pretty big:

//Normal Repeater ItemDataBound
if (e.Item.DataItem is CustomProductDetail)
 
//Telerik ItemDataBound
if ((((RadListViewDataItem)e.Item).DataItem is CustomProductDetail))

0
Veli
Telerik team
answered on 14 Nov 2011, 03:05 PM
Hello Anton,

Thanks for the nice words. The reason you have the DataItem property on the derived RadListViewDataItem type instead of the base RadListViewItem type is because the latter base class is the parent of all types of items in RadListView. Some of these items, like the RadListViewEmptyItem or the RadListViewGroupItem do not have a DataItem property and it wouldn't be semantically correct for them to have one, as these are not databound items.

So, even though we want to keep the structure and API of our controls as close to standard ASP.NET server controls as possible, we also want to be semantically correct when designing APIs. Putting the DataItem property into a base class and then having derived classes where the DataItem is unrelated does not sound like the best we can do. Isn't inheritance supposed to solve exactly these types of issues, i.e. generalizing common properties in a base class and then specializing in a derived class? The databound item is a special case of RadListView item and it should have the DataItem property right in it, not in the base class, where it would be irrelevant for other item types.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Anton Swanevelder
Top achievements
Rank 2
answered on 14 Nov 2011, 03:26 PM
Thanks Veli for your response,

For me it is question of is this class as encapsulated as it could be, since there is no way for me to know that I need to cast the item to a RadListViewDataItem and it will take me considerable digging to discover that if it were not for search engines.

I would more prefer a DataItem of null for non-data aware items than needing to do the cast.

Just my thoughts, you guys are the gurus.

Thanks,
Anton
0
Veli
Telerik team
answered on 14 Nov 2011, 05:53 PM
Feedback well received.

Cheers,
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ListView
Asked by
Roberto Yudice
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Anton Swanevelder
Top achievements
Rank 2
Veli
Telerik team
Share this question
or