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

ItemInserting not firing

1 Answer 127 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 24 Jan 2013, 10:23 PM
Hi,

I have a RadListView where I am dynamically creating the layout template and insert template at runtime.  Also just to let you know, I have the RadListView inside of a RadPanelBar whose ContentTemplate I am also creating at runtime.  This RandPanelBar is within a NestedGridView of a RadGrid.  All that is just an FYI as to the situation :)  I have all of this working, but I am having an issue with inserting a value into my RadListView.  I have a button that resides in the layouttemplate, where when I click it I am rebinding my listview and calling the ShowInsertItem command.  This is correctly showing my Inserttemplate items, where I have a radcombobox and radnumerictextbox. 

At this point after the user fills these things in, I have a save button that is clicked.  This is where my problems lies. I need to be able to get the values of the radCombobox and radnumerictextbox from the edit template.  I tried to access them using FindControl within the save click, but that only finds controls in the layouttemplate.  So I wanted to implement the OnItemInserting event to be able to access the insert template.  At first, I just performed a PerformInsert() call.  But that gave me an error that the list view wasn't in insert mode.  To get around this, I had to call ShowInsertItem again.  By doing that, I can call PerformInsert.  But the event isn't firing, even if I reattach the event to the list view (just to be sure, since it is a dynamic control).  I tried changing my save button's CommandName to 'PerformInsert', but it seems to trigger an insert on the RadGrid and gives an error about it not being in insert mode.  Below is the code in my btnSave_Click event, could someone tell me what I'm doing wrong? Or is there a way within my btnSave_Click event to access the controls in the InsertTemplate?

Thank you!
Richard
rlv.DataSource = rlv.Page.Session[rlv.UniqueID + "_MyItems"]List<MyItem>;
 
rlv.InsertItemTemplate = new CustomTemplate();
rlv.ShowInsertItem(RadListViewInsertItemPosition.LastItem);
 
rlv.PerformInsert(); // calls without error, but no event fired.
rlv.InsertItemPosition = RadListViewInsertItemPosition.None;

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 29 Jan 2013, 04:31 PM
Hi Richard,

You can access the controls in the InsertItemTemplate like shown in the code snippet below:
RadListView1.InsertItem.FindControl("YourControlName")
By using this code you do not need to implement additional logic to obtain a reference to the controls in the insert template.

All the best,
Angel Petrov
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
Richard
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or