Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在delete命令上调用了两次ItemDataBound_Asp.net_Vb.net_Listview_Itemdatabound - Fatal编程技术网

Asp.net 在delete命令上调用了两次ItemDataBound

Asp.net 在delete命令上调用了两次ItemDataBound,asp.net,vb.net,listview,itemdatabound,Asp.net,Vb.net,Listview,Itemdatabound,我对listview有一个问题 当在listview中单击delete按钮时,我会这样做:代码简化,它会按它应该的方式删除 Protected Sub rlvCarts_ItemCommand(sender As Object, e As RadListViewCommandEventArgs) If e.CommandName = RadListView.DeleteCommandName Then mylistItem.i

我对listview有一个问题

当在listview中单击delete按钮时,我会这样做:代码简化,它会按它应该的方式删除

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一次

怎么来的?我怎样才能避免呢?

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


它可以防止在调用命令时自动重新绑定

这种名称混淆会导致错误。在正确的位置使用IsPostBack以避免此两次调用。您可能也在pageload上调用BindData,而不使用apply!isPostBack我正在测试回发,因为它应该在调用listview prerender一次之后进行
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