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

Insert another no longer working

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clinton Smyth
Top achievements
Rank 1
Clinton Smyth asked on 30 Jul 2010, 01:58 AM

Hi

We have a grid that, in edit mode, the user has the options to 'Save this record' or 'Save this record and add another'.  When clicking the 2nd option, the current record should be persisted to the database and a new blank form should be presented to allow the user to enter more data.  Very often we want to prepopulate the form based on the previous entry.  I have the following code to do this:

 

 

 

 

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandSource is LinkButton)
    {
        LinkButton sourceLinkButton = (LinkButton)e.CommandSource;
        if (sourceLinkButton.ID == "SaveThisRecordAndAddAnotherLinkButton")
        {
            e.Item.OwnerTableView.PerformInsert();
            RadGrid1.MasterTableView.IsItemInserted = true;

            
//Prepare an IDictionary with the predefined values
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
            newValues["Remarks"] = "Test remarks";

            
//Insert the item and rebind
            e.Item.OwnerTableView.InsertItem(newValues);
            RadGrid1.Rebind();
            Utils.Log("IsItemInserted:" + RadGrid1.MasterTableView.IsItemInserted);
        }
        else
        {
            RadGrid1.MasterTableView.IsItemInserted = false;
        }
    }
}


What I'm getting is:
  • the current record is persisted correctly to the database
  • NO new insert form is presented to the user
  • a 2nd record with the prepopulated value "Test remarks" is added to the database
  • the Utils.Log debug statement shows in the log that 'IsItemInserted' is set to true

As a test, I placed the statement 'RadGrid1.MasterTableView.IsItemInserted = true;' in the Page_Load event and the grid loaded with the insert form open as expected.
In contrast, if I place the same in the RadGrid1_PreRender event, no insert form appears.

I'm using RadControls_for_ASP.NET_AJAX_2010_1_415_dev_hotfix.zip.

Is the InsertCommand event too late in the page life cycle for 'IsItemInserted = true;' to show the insert form?

What's strange is that we have another web app (implemented in VB) on an earlier version of the Telerik controls and this method works fine!

Please help.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 04 Aug 2010, 08:41 AM
Hello Clinton,

You need to set IsItemInserted="true" and rebind the grid to keep the insert form after the previous one has been saved. I have attached a small test page demonstrating this issue. Note that I have a separate custom command that I handle in RadGrid's ItemCommand event. The custom command first fires the built-int PeformInsert command, then sets the edit form back on and rebinds the grid.

Regards,
Veli
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
Tags
Grid
Asked by
Clinton Smyth
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or