【发布时间】:2014-08-14 08:16:50
【问题描述】:
我有一个位于 UpdatePanel 中的 ASP.NET GridView。在 GridView 我有一个 OnRowCommand 用于从网格中删除或更新行。这一切都很好。这些行正在被删除,用户看到它们从他的屏幕上消失了。一切都应该如此。在其他情况下,用户使用 OnRowCommand 更新这些行上的数量字段。这也很好用。
但是现在,在 UpdatePanel 之外有一个按钮;处理 GridView 行。问题来了。从GridView中删除所有行(记录)后,再点击处理按钮,后面的代码仍然看到GridView.Rows.Count = 1,而不是0。
谁能告诉我一些关于如何更好地利用 UpdatePanel、GridView 和按钮/回发的组合的信息?我确信有办法处理这个问题,这样我就不会遇到这个错误。
一些代码:
protected void gvLines_RowCommand(object sender, GridViewCommandEventArgs e)
{
//fired from a button, on a grid row which sits in an ASP.NET Update Panel!
//some db work to delete a line from the grid.
//bind the grid lines again to correctly see the remaining lines
}
protected void btnConfirmOrder_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gvBasketLines.Rows)
{
//when running this code in a button click/postback,
//ASP.NET still thinks that the line we just removed still exists.
}
}
【问题讨论】:
-
它是否经常返回 1?还是 1 是删除之前的行数?
-
你能显示一些代码吗? OnRowCommand?
-
1 是删除后的计数
-
我用一段简化的代码更新了我的问题