更新面板中具有多个网格视图的Delete_Click事件

时间:2013-07-17 16:16:44

标签: asp.net vb.net gridview

我有一个包含UpdatePanel和5个GridView的页面。我在Gridview外部有一个删除按钮,允许快速删除多个文件。是否可以对所有Gridview使用一个删除按钮单击事件?

  Protected Sub deletePacketBtn_Click(sender As Object, e As EventArgs) Handles deletePacketBtn.Click
    'Loop through all the rows in gridview
    For Each gvrow As C1GridViewRow In packetGrid.Rows
        'Finiding checkbox control in gridview for particular row
        Dim chkdelete As CheckBox = CType(gvrow.FindControl("chkDelete"), CheckBox)
        'Condition to check checkbox selected or not
        If chkdelete.Checked Then
            'Getting ID of particular row using datakey value
            Dim fileID As Integer = Convert.ToInt32(packetGrid.DataKeys(gvrow.RowIndex).Value)
            PacketDataSource.DeleteParameters("original_PKT_Key").DefaultValue = fileID.ToString
            PacketDataSource.Delete()

        End If
    Next
    packetGrid.DataBind()

End Sub

1 个答案:

答案 0 :(得分:0)

是的,sender是导致删除事件的GridView

如果您只是将sender转换为GridView(不知道正确的VB语法,抱歉),您就会知道哪一个导致了该事件。< /击>

以上代码仅适用于GridView的Delete事件,而不适用于按钮单击。