在GridView上删除和维护项目

时间:2014-05-29 05:40:12

标签: asp.net vb.net gridview

对于我发布的上一个问题感到抱歉。所以这是我的问题,这是我的gridview代码。

`

    If e.CommandName = "DeleteItem" Then

        Dim gvItems As GridView = CType(sender, GridView)
        Dim gvparent As GridViewRow = CType(gvItems.NamingContainer, GridViewRow)
        '(gvparent.Cells(2).Text)
        If gvItems.Rows.Count = 1 Then
            lblPopup.Text = "There must be atleast one row."
            mpeError.Show()
            Exit Sub

        End If

        Program.oEquipmentLoan.sTransactionCode = gvparent.Cells(3).Text
        'Dim gvItem As GridView = TryCast(gvitems.FindControl("gvItems"), GridView)
        'For Each gvRow As GridViewRow In gvitems.Rows
        '    Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
        '    If (chkItem.Checked) Then

        '        Program.oEquipmentLoan.iItemNumber = gvRow.Cells(2).Text
        '        oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)

        '    End If
        'Next

        'loadGVGetTransactionLog()

        Dim icount As Integer = 0

        For Each gvRow As GridViewRow In gvItems.Rows

            Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
            If (chkItem.Checked) Then
                icount += 1
            End If

        Next

        If icount > 0 Then

            For Each gvRow As GridViewRow In gvItems.Rows
                Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
                If (chkItem.Checked) Then

                    Program.oEquipmentLoan.iItemNumber = gvRow.Cells(2).Text
                    oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)
                End If
            Next

        Else
            Dim gvr As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            Dim Index As Integer = gvr.RowIndex
            Dim gvRowSelected As GridViewRow = gvItems.Rows(Index)

            Program.oEquipmentLoan.iItemNumber = gvRowSelected.Cells(2).Text
            oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)

        End If


    End If

    sIndex = gvTransactionLogViewer.PageIndex
    blnCount = True
    loadGVGetTransactionLog()

End Sub`

因此,此代码特别删除gridview上的选定行。我的问题是,每当我删除一个项目,删除它后,我无法维护查看列表。

下面给出的图片:

enter image description here

之前部分的照片是我选择要删除的项目时的照片。并在之后,当项目被删除。正如您所看到的,我需要维护的是删除内容后刷新后更新的项目列表。谢谢! :)

1 个答案:

答案 0 :(得分:0)

在.aspx页面上

,您需要进行部分回发以防止整页回发。 你可以使用asp.net ajax更新面板“部分页面呈现”或jquery来实现这一点。