繁体   English   中英

更新面板中的ASP.NET GridView和GridView Row.Count

[英]ASP.NET GridView in Update Panel and GridView Row.Count

我有一个位于UpdatePanel中的ASP.NET GridView。 在GridView上,我有一个OnRowCommand,用于删除或更新Grid中的行。 这一切都很好。 这些行将被删除,用户会看到它们从屏幕上消失了。 一切都应该如此。 在其他情况下,用户使用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.
   }
 }

使用GridView的DataBound事件获取行数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM