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

Automatic InitInsert after PerformInsert

6 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 09 May 2015, 01:35 AM

Hello,

I have a radgrid binded by sql.

What I am trying to implement is a 3rd linkbutton (in addition of Insert and Cancel) triggering consecutively PerformInsert command (to insert new item) and InitInsert (not to have to click again on "Add new".

Anyone got an idea?

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 11 May 2015, 02:40 PM
Hello,

You can use similar approach to the one presented in the article below:
http://www.telerik.com/help/aspnet-ajax/grid-additional-action-button-in-autogenerated-edit-form.html

The only difference is that you need to check if the item is GridDataInsertItem and then add the additional button next to Insert and Cancel buttons:
if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)

Regards,
Pavlina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Christophe
Top achievements
Rank 1
answered on 11 May 2015, 05:40 PM

Thank you Pavlina for your reply.

I added this Code:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        GridDataItem dataItem = ((GridDataItem)(e.Item));
        LinkButton linkButton = new LinkButton();
        // adding delete button as third
        linkButton.Text = "Delete";
        linkButton.Attributes["onclick"] = "javascript:return confirm(\'Do you want to delete this item?\')";
        linkButton.CommandName = "Delete";
        dataItem["EditCommandColumn"].Controls.Add(new LiteralControl(" "));
        dataItem["EditCommandColumn"].Controls.Add(linkButton);
    }
}

But no third button appears. And adding:

      <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
      </telerik:GridEditCommandColumn>

leads to the following: "Plusieurs contrôles avec le même ID 'EditButton' ont été trouvés. FindControl requiert que les contrôles aient des ID uniques."

0
Pavlina
Telerik team
answered on 14 May 2015, 05:00 PM
Hi,

Change the code as shown below and you should be able to see Delete button when you enter in insert mode:
​
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridDataInsertItem dataItem = e.Item as GridDataInsertItem;
            LinkButton linkButton = new LinkButton();
            // adding delete button as third
            linkButton.Text = "Delete";
            linkButton.Attributes["onclick"] = "javascript:return confirm(\'Do you want to delete this item?\')";
            linkButton.CommandName = "Delete";
            dataItem["EditCommandColumn"].Controls.Add(new LiteralControl(" "));
            dataItem["EditCommandColumn"].Controls.Add(linkButton);
        }
    }

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Christophe
Top achievements
Rank 1
answered on 14 May 2015, 10:19 PM

Hello Pavlina,

I am sorry but no button is appearing.

Would you have an sample file working?

0
Pavlina
Telerik team
answered on 15 May 2015, 06:18 AM
Hello,

You can find attached my test project.

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Christophe
Top achievements
Rank 1
answered on 15 May 2015, 06:44 PM

Thank you Pavlina,

It still doen't work for me, meaning that the new button does not appear.

To make it appear, I must state  EditMode="InPlace" like you did.

But in this case, as I am using  <EditFormSettings EditFormType="Template">, my code does not work anymore...

Tags
Grid
Asked by
Christophe
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Christophe
Top achievements
Rank 1
Share this question
or