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

[Solved] radgrid delete command

1 Answer 503 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 24 Jul 2009, 04:43 PM
I have encountered a strange issue I havent come accross before regarding the delete command of a radgrid.  
1.  User clicks the edit link on a row
2.  User clicks delete on a different row while the edit row is still open
3.  User clicks Add new and recieves the message "you may only have one item open at a time"

The issue seems to be that the radgrids editindexes.count is still at one when the user clicks delete even though the row in edit mode visually closes.

I am handling the deletecommand but all I am doing is reading in the id to delete from e.commandargument and deleting it.
Is there something I need to do in the deletecommand to get the editindexes to reload?

The simple solution would be to not let the user delete, but there has to be another solution...





    Protected Sub rg_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rg.ItemCommand

        lblMessage.Text = ""

        If (e.CommandName = RadGrid.InitInsertCommandName) Then

            If ((CType(source, RadGrid).EditIndexes.Count > 0) _

                        OrElse e.Item.OwnerTableView.IsItemInserted) Then

 

                prjUtilities.showFeedback(lblMessage, "*You may only have one item open at a time", True)

                e.Canceled = True

                cblExpenses.Enabled = False

            Else

                e.Canceled = True

                Dim off As New offType

                e.Item.OwnerTableView.InsertItem(off)

                'Hides the edit column when in create mode

                Dim editColumn As GridEditCommandColumn = CType(CType(source, RadGrid).MasterTableView.GetColumn("edit"), GridEditCommandColumn)

                editColumn.Visible = False

                cblExpenses.Enabled = False

            End If

        ElseIf e.CommandName = "PerformInsert" Then

            Dim editColumn As GridEditCommandColumn = CType(CType(source, RadGrid).MasterTableView.GetColumn("edit"), GridEditCommandColumn)

            If Not editColumn.Visible Then

                editColumn.Visible = True

            End If

 

            cblExpenses.Enabled = True

        ElseIf e.CommandName = "Cancel" Then

            cblExpenses.Enabled = True

            prjUtilities.showFeedback(lblMessage, "Changes Cancelled", False)

            Dim editColumn As GridEditCommandColumn = CType(CType(source, RadGrid).MasterTableView.GetColumn("edit"), GridEditCommandColumn)

            If Not editColumn.Visible Then

                editColumn.Visible = True

            End If

        Else

            'reset the edit column to visible

            cblExpenses.Enabled = False

            Dim editColumn As GridEditCommandColumn = CType(CType(source, RadGrid).MasterTableView.GetColumn("edit"), GridEditCommandColumn)

            If Not editColumn.Visible Then

                editColumn.Visible = True

            End If

        End If

    End Sub



<telerik:RadGrid ID="rg" runat="server" AllowPaging="True" AutoGenerateColumns="False"

            GridLines="None" Skin="Office2007">

            <HeaderContextMenu>

                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

            </HeaderContextMenu>

            <MasterTableView CommandItemDisplay="Top">

                <CommandItemTemplate>

                    <table>

                        <tr>

                            <td width="30%">

                                <asp:ImageButton ID="btnAddImbtn" runat="server" CommandName="InitInsert" CausesValidation="false"

                                    ImageUrl="~/images/RadControls Skins/Office2007/Grid/AddRecord.gif" />

                                <asp:LinkButton ID="btnAddlkbtn" runat="server" Font-Bold="true" CausesValidation="false"

                                    CommandName="InitInsert">Click Here to Add New</asp:LinkButton>

                            </td>

                            <td width="40%">

                            </td>

                            <td width="30%">

                            </td>

                        </tr>

                    </table>

                </CommandItemTemplate>

                <EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/ucOff.ascx" />

                <Columns>

                    <telerik:GridEditCommandColumn EditText="Edit" UniqueName="edit" />

                    <telerik:GridBoundColumn DataField="offid" UniqueName="offid"

                        HeaderText="offid" Visible="false">

                    </telerik:GridBoundColumn>

                    <telerik:GridTemplateColumn UniqueName="del">

                        <ItemTemplate>

                            <asp:LinkButton ID="lblDelete" runat="server" Text="Delete" CommandName="Delete"

                                CommandArgument='<%#Eval("offid")%>' CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>

                        </ItemTemplate>

                    </telerik:GridTemplateColumn>

                </Columns>

            </MasterTableView>

        </telerik:RadGrid>

               

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 29 Jul 2009, 09:54 AM
Hi eric,

Try downloading the latest version of the controls to include it in your implementation and if the problem persists, I'd ask you to modify the attached sample so that the behavior is observed and send it back to us for further investigation.

Best Regards,
Tsvetoslav
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.
Tags
Ajax
Asked by
eric
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or