RadGrid DeleteCommand error

2 posts, 0 answers
  1. Marc
    Marc avatar
    8 posts
    Member since:
    Aug 2016

    Posted 04 Nov Link to this post

    Hello all,

    I have a Radgrid with a DeleteColumn. When I click in delete image the row dessapear but when I refresh the grid the row appear again.

    I try with Datasource delete query and code behind, but OnDeleteCommand never triggered.

    Code:

     

    <telerik:RadGrid  ID="RGVEmpresasEnCentro" runat="server" Width="500px"
                                    RenderMode="Lightweight" GridLines="None" 
                                    AllowAutomaticDeletes="true"
                                    AllowAutomaticInserts="true"
                                    PageSize="10"
                                    OnPreRender="RGVEmpresasEnCentro_PreRender"
                                    OnBatchEditCommand="RGVEmpresasEnCentro_BatchEditCommand"
                                    OnDeleteCommand="RGVEmpresasEnCentro_DeleteCommand"
                                    AllowAutomaticUpdates="true"
                                    AllowPaging="true"
                                    AutoGenerateColumns="False"
                                    DataSourceID="SDSEmpresasEnCentro"
                                    Skin="WebBlue" >
                    <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="id"
                        DataSourceID="SDSEmpresasEnCentro" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"
                        CommandItemSettings-AddNewRecordText="Insertar centro"
                        CommandItemSettings-SaveChangesText="Guardar"
                        CommandItemSettings-CancelChangesText="Cancelar"
                        CommandItemSettings-RefreshText="Refrescar"
                        NoMasterRecordsText="No hay empresas en el centro"
                        NoDetailRecordsText="No hay empresas en el centro">
                        <BatchEditingSettings EditType="Cell" />
                        <Columns>
                            <telerik:GridBoundColumn    DataField="id"
                                                        Visible="false"
                                                        DataType="System.Int32"
                                                        HeaderText="id"
                                                        SortExpression="id"
                                                        UniqueName="id"
                                                        ReadOnly="true"  />
                            <telerik:GridBoundColumn DataField="Empresa"
                                HeaderText="Empresa"
                                SortExpression="Empresa"
                                UniqueName="Empresa">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Numero"
                                HeaderText="Numero"
                                SortExpression="Numero"
                                UniqueName="Numero">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="Desde"
                                HeaderText="Desde"
                                SortExpression="Desde"
                                UniqueName="Desde" PickerType="DatePicker" DataFormatString="{0:dd/MM/yyyy}" >
                            </telerik:GridDateTimeColumn>
                            <telerik:GridDateTimeColumn DataField="HastaEl" 
                                HeaderText="Hasta el"
                                SortExpression="HastaEl"
                                UniqueName="HastaEl"
                                PickerType="DatePicker"
                                DataFormatString="{0:dd/MM/yyyy}" >
                            </telerik:GridDateTimeColumn>
                             <telerik:GridButtonColumn
                                 HeaderText="Delete" HeaderStyle-Width="50px"
                                CommandName="Delete"  Text="Delete" UniqueName="DeleteColumn">
                            </telerik:GridButtonColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
                </telerik:RadGrid>
     
            <asp:SqlDataSource ID="SDSEmpresasEnCentro" runat="server" ConnectionString="<%$ ConnectionStrings:PCMConnectionString %>"
                                SelectCommand="SELECT * From EmpresasEnCentros Where idRevisionCentros=@idRevisionCentros"
                                DeleteCommand="DELETE EmpresasEnCentros WHERE id = @id"
                                InsertCommand="INSERT INTO EmpresasEnCentros (idRevisionCentros,Empresa,Numero,Desde,HastaEl) VALUES (@idRevisionCentros,@Empresa,@Numero,@Desde,@HastaEl)"
                                UpdateCommand="UPDATE EmpresasEnCentros SET Empresa=@Empresa, Numero=@Numero,Desde=@Desde,HastaEl=@HastaEl WHERE id = @id">
                <DeleteParameters>
                    <asp:Parameter Name="id" Type="Int32"></asp:Parameter>
                </DeleteParameters>
                <SelectParameters>
                    <asp:parameter Name="idRevisionCentros" DefaultValue="0" type="Int32" />
                </SelectParameters>
                <InsertParameters>
                    <asp:parameter Name="idRevisionCentros" type="Int32" />
                    <asp:Parameter Name="Empresa" Type="String"></asp:Parameter>
                    <asp:Parameter Name="Numero" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Desde" Type="DateTime"></asp:Parameter>
                    <asp:Parameter Name="HastaEl" Type="DateTime"></asp:Parameter>
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="id" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Empresa" Type="String"></asp:Parameter>
                    <asp:Parameter Name="Numero" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Desde" Type="DateTime"></asp:Parameter>
                    <asp:Parameter Name="HastaEl" Type="DateTime"></asp:Parameter>
                </UpdateParameters>
            </asp:SqlDataSource>

     

    protected void RGVEmpresasEnCentro_PreRender(object sender, EventArgs e)
        {
            RGVEmpresasEnCentro.Rebind();
            GridTableView masterTable = (sender as RadGrid).MasterTableView;
            foreach (GridColumn column in masterTable.RenderColumns)
            {
                if ((column is IGridEditableColumn) && (column as IGridEditableColumn).IsEditable && masterTable.GetBatchColumnEditor(column.UniqueName) != null)
                {
                    Control container = (masterTable.GetBatchColumnEditor(column.UniqueName) as IGridColumnEditor).ContainerControl;
                    if (container != null && container.Controls.Count > 0)
                    {
                        (container.Controls[0] as WebControl).Width = Unit.Percentage(100);
                    }
                }
            }
        }
    protected void RGVEmpresasEnCentro_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if(command.Type == GridBatchEditingCommandType.Insert)
                {
                    Hashtable newValues = command.NewValues;
                    if(!newValues.ContainsValue(null))
                    {
                        string centro = Request.QueryString["Centro"];
                        string periodo = Request.QueryString["Periodo"];
                        int idRevisionCentro =CentrosBLL.ComprobarYCrearRegistros(centro, periodo, Session["codigoSap"].ToString());
                        string empresa = newValues["Empresa"].ToString();
                        int numero = Convert.ToInt32(newValues["Numero"]);
                        DateTime desde = Convert.ToDateTime(newValues["Desde"]);
                        DateTime hasta=Convert.ToDateTime(newValues["HastaEl"]);;
                        CentrosBLL.insertEmpresaCentro(idRevisionCentro,empresa,numero,desde,hasta);
                    }
                    e.Canceled = true;
                }
            }
        }
        protected void RGVEmpresasEnCentro_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            //Some code for delete programatically
        }
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Nov Link to this post

    Hi,

    The observed behavior is expected because BatchEditCommand event is not firing on row deletion. I want to inform you that this is due to the fact that you have to click on the Save changes button in order to fire the event. The main goal of Batch edit mode is to provide functionality for inline client-side editing, performing multiple changes before applying them.

    Regards,
    Pavlina
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top