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

[Solved] delete link on radgrid performs delete function on edit mode

4 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pinkey
Top achievements
Rank 1
Pinkey asked on 01 Jul 2009, 06:53 AM
Hi,
I have a RadGrid with delete and edit link as one of its columns. If i edit  a record, it opens in Editform on grid.
When working on edit form of rad grid if I click on Delete link on radgrid at the back of editform, it still performs the delete operation
even though one record is in edit mode.
following is the way by which I am declaring the Delete link.

 

<telerik:GridTemplateColumn UniqueName="DeleteColumn" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center">

 

<ItemTemplate>

 

 

 

          <asp:LinkButton runat="server" CausesValidation="false" OnClientClick ="if (confirm('Are You Sure You Wish To Delete This Item?'))return true; else return false;"  CommandName="Delete" Text="Delete" ID="btnDelete" ForeColor="Blue"></asp:LinkButton> </ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

Please guide me how i can avoid this?

Thanks
Pinkey

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Jul 2009, 07:21 AM
Hello Pinkey,

You can disable the Delete buttons when RadGrid is in Edit mode.
<telerik:GridTemplateColumn HeaderText="Delete"
    <ItemTemplate> 
        <asp:LinkButton runat="server" Enabled='<%# RadGrid1.EditIndexes.Count == 0 %>' Text="Delete" 
            CommandName="Delete" /> 
    </ItemTemplate> 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Jul 2009, 07:44 AM
Hello,

I am sure that the above code will work fine. But when I tried on my end, the confirmation is shown evenif the LinkButton is disabled. So I tried following code to avoid confirmation window when the row is in Editmode.

ASPX:
 
<telerik:GridTemplateColumn UniqueName="DeleteColumn" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center">  
    <ItemTemplate> 
        <asp:LinkButton runat="server" CausesValidation="false" OnClientClick="if (confirm('Are You Sure You Wish To Delete This Item?'))return true; else return false;" 
            CommandName="Delete" Text="Delete" ID="btnDelete" ForeColor="Blue"></asp:LinkButton> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

C#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)  
    {  
        GridEditableItem editItem = e.Item as GridEditableItem;  
        GridDataItem item = (GridDataItem)((Telerik.Web.UI.GridEditFormItem)(editItem)).ParentItem;  
        LinkButton btnDelete = (LinkButton)item.FindControl("btnDelete");  
        btnDelete.Enabled = false;  
        btnDelete.OnClientClick = null;  
    }  

Thanks,
Princy.
0
Accepted
Daniel
Telerik team
answered on 01 Jul 2009, 08:44 AM
Princy, thank you the comment.

This "limitation" could be easily avoided with a simple check:

Example:
... OnClientClick="if (this.disabled) return false; if (confirm('Are You Sure You Wish To Delete This Item?'))return true; else return false;" /> 

Keep up the good work.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Pinkey
Top achievements
Rank 1
answered on 01 Jul 2009, 02:38 PM
Hello,

   Thanks to Daniel and Princy, 
My issue is resolved 
Tags
Grid
Asked by
Pinkey
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Princy
Top achievements
Rank 2
Pinkey
Top achievements
Rank 1
Share this question
or