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

[Solved] CheckBox in Grid

1 Answer 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abdul Kadar
Top achievements
Rank 1
Abdul Kadar asked on 03 Oct 2009, 08:56 AM
Hi,
My Scenario is , I want to delete the selected items( selected using checkbox)  in the grid by clicking on the delete link button using code-behind in vb.Please help me

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Oct 2009, 05:30 AM
Hi Abdul Kadar,

Here is the example which I tried to delete the selected row on clicking the LinkButton.

ASPX:
 
<CommandItemTemplate> 
    <asp:LinkButton ID="LinkButton1" Text="Delete Selected"  
        runat="server" OnClick="LinkButton1_Click"></asp:LinkButton> 
</CommandItemTemplate> 
<Columns> 
    <telerik:GridTemplateColumn UniqueName="CopyEmail" HeaderText="Copy?"
        <ItemTemplate> 
            <asp:CheckBox ID="CheckBox1" runat="server" Checked="false" TextAlign="Right" /> 
        </ItemTemplate> 
        <EditItemTemplate> 
            . . . 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" 
    UniqueName="CustomerID"
</telerik:GridBoundColumn> 
</Columns> 

VB:
 
Protected Sub LinkButton1_Click(ByVal sender As ObjectByVal e As EventArgs) 
    For Each item As GridDataItem In RadGrid1.MasterTableView.Items 
        Dim chk As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox) 
        If chk.Checked Then 
                ' Prepare query  using the 'key' and execute to delete the record 
            Dim key As String = item("CustomerID").Text 
        End If 
    Next 
End Sub 

You can also simply set the CommandName of LinkButton to "DeleteSelected" for deleting he selected rows without writing any code.

-Shinu.
Tags
Grid
Asked by
Abdul Kadar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or