Asp.net 在delete命令上调用了两次ItemDataBound
我对listview有一个问题 当在listview中单击delete按钮时,我会这样做:代码简化,它会按它应该的方式删除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
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