[英]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.