Access object from ShowInsertItem

4 posts, 0 answers
  1. Senate Public Information Office
    Senate Public Information Office avatar
    4 posts
    Member since:
    Oct 2008

    Posted 07 Aug 2013 Link to this post

    Hi
    I am using a RadListView to display items of three similar object types (Member, Position, Substitute), and use code-behind to show/hide fields within the templates depending on the type of the object. So far, I have view and edit working fine, using a UserControl that detects the object type,and updates the display accordingly. My problem occurs when I try to add.

    I have three buttons on the form, one for adding each object type, firing different commands for each type - AddMember, AddPosition, AddSubstitute. When the command is fired, I create an empty object of the required type, and use the RadListView's ShowInsertItem method with the object parameter overload.

    My question is, how can I access this object from my asp.net markup, so I can pass it through to the UserControl that defines the fields to use?

    In the EditTemplate, I can simply use something like:

    <scid:EditControl runat="server" ID="EditObject" Member="<%# (BaseMemberCommon)Container.DataItem %>"/>

    However, in the InsertTemplate, the Container object doesn't have a DataItem property.

    Can anyone help?
    Thanks




  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 09 Aug 2013 Link to this post

    Hi Matt,

    Generally you should be able to obtain a reference to the DataItem property. I tried reproducing the problem in a sample project but was unable to do so. Could you please examine the attached website and tell us what differs from the approach you have implemented? If you can modify the logic so that the issue is reproducible we should be able to provide a more precise answer.

    Regards,
    Angel Petrov
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Senate Public Information Office
    Senate Public Information Office avatar
    4 posts
    Member since:
    Oct 2008

    Posted 11 Aug 2013 Link to this post

    Hi Angel

    Thanks for your reply.

    However, when I attempt to build the code you supplied, I get the following error message (which is the same one that first prompted this thread):

    'Telerik.Web.UI.RadListViewItem' does not contain a definition for 'DataItem' and no extension method 'DataItem' accepting a first argument of type 'Telerik.Web.UI.RadListViewItem' could be found (are you missing a using directive or an assembly reference?)

    I suspect that the problem may have something to do with the fact that the project is a web site, rather than a web project (it's an old, legacy project which is currently not important enough to be upgraded).

    I have figured out an alternate solution to my problem, which is to put the insertion object into session, and access it from there. It's quite small, and not that much of an overhead, and it seems to be working. I would like to know the cause of the problem, though, if you have any insights.

    Thanks
    Chris (Matt is my boss, and the holder of the licenses. I have since created my own account which I will post any future questions)
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 15 Aug 2013 Link to this post

    Hi Chris,

    I am glad that you have found an alternative solution. However providing an accurate answer about why are you experiencing the problem on the first place would be hard without reproducing it locally. I have created a sample website in which to replicate the problem by using the previously provided pages but in my case all worked as expected. That said I would like to ask you to show us the markup and code-behind of the problematic page so we could investigate further.

    Regards,
    Angel Petrov
    Telerik
    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 the blog feed now.
Back to Top