Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListView > Access DataItem property of ListView databound Item

Not answered Access DataItem property of ListView databound Item

Feed from this thread
  • Roberto Yudice avatar

    Posted on May 10, 2010 (permalink)

    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?

    Reply

  • Nikolay Rusev Nikolay Rusev admin's avatar

    Posted on May 11, 2010 (permalink)

    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.

    Reply

  • Posted on Nov 13, 2011 (permalink)

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

    Reply

  • Veli Veli admin's avatar

    Posted on Nov 14, 2011 (permalink)

    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

    Reply

  • Posted on Nov 14, 2011 (permalink)

    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

    Reply

  • Veli Veli admin's avatar

    Posted on Nov 14, 2011 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListView > Access DataItem property of ListView databound Item
Related resources for "Access DataItem property of ListView databound Item"

ASP.NET ListView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]