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

Access object from ShowInsertItem

3 Answers 102 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Senate Public Information Office
Top achievements
Rank 1
Senate Public Information Office asked on 07 Aug 2013, 05:51 AM
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




3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 09 Aug 2013, 02:01 PM
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.
0
Senate Public Information Office
Top achievements
Rank 1
answered on 11 Aug 2013, 09:56 PM
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)
0
Angel Petrov
Telerik team
answered on 15 Aug 2013, 06:05 AM
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.
Tags
ListView
Asked by
Senate Public Information Office
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Senate Public Information Office
Top achievements
Rank 1
Share this question
or