Access DataItem property of ListView databound Item

6 posts, 0 answers
  1. Roberto Yudice
    Roberto Yudice avatar
    16 posts
    Member since:
    Mar 2010

    Posted 10 May 2010 Link to this post

    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?
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 11 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anton Swanevelder
    Anton Swanevelder avatar
    28 posts
    Member since:
    Aug 2008

    Posted 13 Nov 2011 Link to this post

    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))

  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 14 Nov 2011 Link to this post

    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
  6. Anton Swanevelder
    Anton Swanevelder avatar
    28 posts
    Member since:
    Aug 2008

    Posted 14 Nov 2011 Link to this post

    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
  7. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 14 Nov 2011 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017