Question

My code is:

<ext:GridPanel ID="GridEmployees" runat="server" Width="700" Title="Employees">
    <Store>
        <ext:Store ID="StoreEmployees" runat="server">
            <Model>
                <ext:Model ID="ModelEmployees" runat="server" IDProperty="ID">
                    <Fields>
                        <ext:ModelField Name="ID" Type="Int" />
                        <ext:ModelField Name="Name" Type="String" />
                    </Fields>
                </ext:Model>
            </Model>
        </ext:Store>
    </Store>
    <ColumnModel>
        <Columns>
            <ext:Column ID="ColumnName" Text="Name" runat="server" Flex="1" DataIndex="Name"/>
        </Columns>
    </ColumnModel>
    <SelectionModel>
        <ext:CheckboxSelectionModel runat="server" Mode="Multi" />    
    </SelectionModel>
    </ext:GridPanel>

I want to delete selected rows from the gridpanel and, the employees with selected IDs from the 'Employee' table when a button is clicked. Please how can I do this with linq to sql (with/without lambda)? Thank You.

No correct solution

OTHER TIPS

Add this markup into grid:

    <TopBar>
        <ext:Toolbar runat="server">
            <items>
                <ext:Button runat="server" Handler="
                    var idArray = new Array();
                    var selection = #{GridEmployees}.getSelectionModel().getSelection();
                    for(i in selection){
                        idArray.push(selection[i].data.id);
                    }
                    App.direct.DeleteSelected(idArray);" />
            </items>
        </ext:Toolbar>
    </TopBar>

And this code into code behiend:

dataContext ctx = new dataContext(); // your data context

[DirectMethod]
public void DeleteSelected(int[] idArray)
{
    ctx.Employees.DeleteAllOnSubmit(
        ctx.Employees.Where(x => idArray.Contains(x.id)).ToArray()
    );
    ctx.SubmitChanges();
}

Or this code:

[DirectMethod]
public void DeleteSelected(int[] idArray)
{
    ctx.ExecuteCommand(
        string.Format(
            "DELETE FROM Employees WHERE ID IN ({0})",
            string.Join(",", idArray.Select(x => x.ToString()).ToArray())
        )
    );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top