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
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.
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."
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
Hello Pavlina,
I am sorry but no button is appearing.
Would you have an sample file working?
You can find attached my test project.
Regards,
Pavlina
Telerik
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...