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

Delete all selected items

5 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 20 Jan 2009, 10:56 PM
following this demo http://demos.telerik.com/aspnet-ajax/Grid/Examples/Programming/SelectRowWithCheckBox/DefaultCS.aspx
I manged it to selects all the rows .. now i would like to delete all selected items from the database by clicking the Delete Button which is not part of the radGrid .. just a common Button to the top of the page.
Column 1 which holds the primary key look like following:

<telerik:GridTemplateColumn Visible="false"
    <ItemTemplate><asp:Label ID="ID" runat="server" Text='<%# Eval("ID") %>'></asp:Label></ItemTemplate
</telerik:GridTemplateColumn>  




Thank you

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Jan 2009, 03:52 AM
Hi,

You can loop through the selected items and then delete the items as shown below:
protected void Button2_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
           //delete query 
        } 
    } 

Thanks
Princy.
0
El
Top achievements
Rank 1
answered on 21 Jan 2009, 07:51 AM
Hi Princy,

Thanks for the reply .. it makes sense but i need to get the ID value of the selected row and then proceed to the sql query.
Something along this line:
String strSQL = "Delete * From Table Where ID=" + item.ID + "";

Btw, i didn't know that you can iterate the selected items collection in that way. This is great news !

Thanks for any further help


0
El
Top achievements
Rank 1
answered on 21 Jan 2009, 09:14 AM
I think i've found it!

For Each item As GridDataItem In RadGrid1.SelectedItems 
    Dim lblID As Label = CType(item.FindControl("ID"), Label) 
    ' ToDo: call the delete query  
Next 

Please just if you can confirm that this is the right way for deleting all selected items.

Thanks
0
Sebastian
Telerik team
answered on 21 Jan 2009, 09:21 AM
Hello El,

Indeed this seems to be a valid solution for deleting the selected items in the grid. Alternatively, you can consider the codeless approach with data source control assigned for item generator demonstrated here (taking advantage of the event bubbling mechanism of RadGrid).

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
El
Top achievements
Rank 1
answered on 21 Jan 2009, 10:32 AM
this is so cool...  much appreciated! Thanks :)
Tags
Grid
Asked by
El
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
El
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or