ItemDataBound在delete命令上调用两次

时间:2012-06-14 10:02:29

标签: asp.net vb.net listview itemdatabound

我对listview存在问题。

我在列表视图中单击删除按钮时这样做:(代码简化,删除它应该)

Protected Sub rlvCarts_ItemCommand(sender As Object, e As RadListViewCommandEventArgs)
        If e.CommandName = RadListView.DeleteCommandName Then
                           mylistItem.items.RemoveAt(e.CommandArgument.ToString)                    
            BindData()            
        End If
End Sub

 Protected Sub BindData()
     rlvCarts.DataSource = mylistItem.items
     rlvCarts.DataBind()
 End Sub

问题出现时,删除它会执行两次itemdatabound(但listview prerender一次)。

它是怎么来的?我怎么能避免这种情况?

1 个答案:

答案 0 :(得分:0)

已解决:我必须添加e.Canceled = True

Protected Sub rlvCarts_ItemCommand(sender As Object, e As RadListViewCommandEventArgs)
        If e.CommandName = RadListView.DeleteCommandName Then
                           mylistItem.items.RemoveAt(e.CommandArgument.ToString)   
            e.Canceled = True     
            BindData()            
        End If
End Sub

当命令被调用

时,它会阻止“自动重新绑定”