在我的gridview上,我将一个javascript OnClick方法关联到一个linkbuton,它要求确认删除有界行:
protected void DeleteRow_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
{
string cartId = usersShoppingCart.GetCartId();
int rowIndex = grdrow.RowIndex;
//int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
string itemId = ((HiddenField)CartList.Rows[rowIndex].FindControl("hiddenEncryptedItemID")).Value;
usersShoppingCart.RemoveItemWithOptionsAndValues(cartId, itemId);
CartList.DataBind();
lblTotal.Text = String.Format("{0:N2}", usersShoppingCart.GetTotal());
//return usersShoppingCart.GetCartItems();
}
}
出于美观原因,我以这种方式构建了我的ItemTemplate:
<ItemTemplate>
<div class="divItemTotal">
<div>
<asp:Label runat="server" CssClass="totalItem" ID="lblItemTotalPrice" Text='<%#: String.Format("{0:N2}", ((Convert.ToDouble(Item.Quantity)) * Convert.ToDouble(Item.UnitPrice)))%>'></asp:Label>
<asp:Label runat="server" ID="lblCurrency2" Text=" €"></asp:Label></div>
<asp:LinkButton OnClick="DeleteRow_Click" CssClass="removeItem imgRemoveItem" runat="server" ID="DeleteRow"></asp:LinkButton>
</div>
在一个完美的世界中,javascript方法应该阻止页面执行回发并在确认时将其释放。不幸的是,点击确定没有任何反应,ASP.net方法永远不会被触发。更糟糕的是,在没有javascript函数的情况下,asp方法只会不时触发,我仍然没有假设。
答案 0 :(得分:0)
试试这个:
removeAll()
代码背后:
removeAll()