简体   繁体   English

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

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

I have an ASP.NET GridView that sits in an UpdatePanel. 我有一个位于UpdatePanel中的ASP.NET GridView。 On the GridView i have a OnRowCommand which is used to delete or update rows from the Grid. 在GridView上,我有一个OnRowCommand,用于删除或更新Grid中的行。 This all works fine. 这一切都很好。 The rows are being deleted, and the user sees them disappearing from his screen. 这些行将被删除,用户会看到它们从屏幕上消失了。 All as it should. 一切都应该如此。 In other cases users use a OnRowCommand to update the quantity field on these rows. 在其他情况下,用户使用OnRowCommand更新这些行上的数量字段。 That also works fine. 那也很好。

But now, outside of that UpdatePanel there is a button; 但是现在,在该UpdatePanel外部有一个按钮; Process GridView lines. 处理GridView行。 And here comes the problem. 问题来了。 After removing all the rows (records) from the GridView, and then clicking on the process button, the code behind still sees GridView.Rows.Count = 1, instead of 0. 从GridView中删除所有行(记录),然后单击“处理”按钮后,后面的代码仍然看到GridView.Rows.Count = 1,而不是0。

Can anyone point me at some info on how to make better use of this combination of UpdatePanel, GridView and button/postback? 任何人都可以向我指出一些有关如何更好地利用UpdatePanel,GridView和按钮/回发的组合的信息吗? I'm sure there is a way to handle this so that i dont run into this error. 我敢肯定有一种方法可以解决这个问题,这样我就不会遇到这个错误。

Some code: 一些代码:

 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