还是那句话出错:(System.InvalidCastException: Specified cast is not valid.
are you using a Button? if you are, the syntax looks ok, seehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsdatagridcommandeventargsclasscommandsourcetopic.asp Sub Grid_CartCommand(sender As Object, e As DataGridCommandEventArgs)
If CType(e.CommandSource, Button).CommandName = "AddToCart" Then ' Insert code to add an item to cart. Else ' Insert code to remove an item from the cart. End If ShoppingCart.DataBind() End Sub 'Grid_CartCommand
Sub Grid_CartCommand(sender As Object, e As DataGridCommandEventArgs)
If CType(e.CommandSource, Button).CommandName = "AddToCart" Then
' Insert code to add an item to cart.
Else
' Insert code to remove an item from the cart.
End If
ShoppingCart.DataBind()
End Sub 'Grid_CartCommand
CType(e.CommandSource, Button)。转换成button阿<asp:ButtonColumn HeaderText="删除" Text="删除" CommandName="del" />