Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
Issue deleting records
posted

Hi,

I am having an issue deleting records from my grid, which I am binding to an ObjectDataSource.

Code below:

function doDeleteRows() {

            var valid = true;
    
            var gridRows = grid.get_rows();
            var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();

            // do we have any rows selected
            if (selectedRows.length == 0) {
                valid = false;
                displayPageTextMessage("You must select at least one row to delete.", true);
            }
            else {

                var confirmation;
                if (selectedRows._keys.length == 1) {
                    confirmation = "Are you sure you want to delete the selected line (1 record)?";
                }
                else {
                    confirmation = "Are you sure you want to delete the selected line (" + selectedRows._keys.length + " records)?";
                }

                valid = confirm(confirmation);
            }

            if (valid) {

                for (var i = selectedRows.get_length() - 1; i >= 0; i--) {
                    var row = selectedRows.getItem(i);
                    gridRows.remove(row);
                }

                displayPageTextMessage("Deleted succesfully.", true);
            }


            return false;
        }

<ig:WebDataGrid ID="myGrid" DataKeyFields="account_line_id, CSBALine" runat="server"
            Width="100%" Height="100%"
            DataSourceID="odsAccountLineList" AutoGenerateColumns="false"
            StyleSetName="ElectricBlue"
            Font-Names="Arial Monospaced">
            <ClientEvents Initialize="myGrid_Initialize" />
            <Behaviors>    
                <ig:Activation Enabled="true"></ig:Activation>
                <ig:ColumnMoving DragStyle="Follow" Enabled="true">
                    <ColumnSettings>
                        <ig:ColumnMoveSetting ColumnKey="Attachment" EnableMove="false" />
                        <ig:ColumnMoveSetting ColumnKey="CSBALine" EnableMove="false" />
                    </ColumnSettings>
                </ig:ColumnMoving>
                <ig:ColumnResizing Enabled="true"></ig:ColumnResizing>
                <ig:EditingCore>
                    <Behaviors>
                        <ig:CellEditing Enabled="true" EditModeActions-MouseClick="Double" EditModeActions-EnableOnKeyPress="true">
                        </ig:CellEditing>
                    </Behaviors>
                </ig:EditingCore>
                <ig:Paging Enabled="false" ></ig:Paging>
                <ig:RowSelectors Enabled="true"></ig:RowSelectors>
                <ig:Sorting Enabled="false"></ig:Sorting>
                <ig:Selection CellClickAction="Cell" CellSelectType="None" ColumnSelectType="None" RowSelectType="Multiple"></ig:Selection>
            </Behaviors>
        </ig:WebDataGrid>

        <asp:ObjectDataSource ID="odsAccountLineList" runat="server"
                              TypeName="BusinessManager"
                              EnablePaging="false"
                              SelectMethod="GetAccountLineDataTableForWebGrid" OnSelecting="odsAccountLineList_Selecting"
                              UpdateMethod="UpdateAccountLine" OnUpdating="odsAccountLineList_Updating"
                              DeleteMethod="DeleteAccountLine">

            <SelectParameters>
                <asp:Parameter Name="subcommitteeId" />
                <asp:Parameter Name="fiscalYear" />
                <asp:Parameter Name="filters" />
                <asp:Parameter Name="user" />
            </SelectParameters>

            <DeleteParameters>
                <asp:ControlParameter ControlID="hfFiscalYear" Type="String" Name="fiscalYear" PropertyName="Value" />
                <asp:Parameter Name="account_line_id" Type="Int32" />                
            </DeleteParameters>

        </asp:ObjectDataSource>

I have a menu item on the page that calls doDeleteRows(). I get the error message selecting  one or multiple rows. The error says:

InvalidOperationException

ObjectDataSource 'odsAccountLineList' could not find a non-generic method 'DeleteAccountLine' that has parameters: fiscalYear, account_line_id, CSBALine.

However, I do have a method as such. In fact, I even created a method stub with the third parameter just to trick it as below:

<DataObjectMethod(DataObjectMethodType.Delete)>
    Public Shared Function DeleteAccountLine(ByVal fiscalYear As String, ByVal account_line_id As Integer, ByVal CSBALine As Integer) As Boolean
        ' delete the record
        CSBADAL.DeleteAccountLine(fiscalYear, account_line_id)

        Return True

    End Function

Your help is very appreciated.

P.S. what's the proper way to post code in tags on here?