2012-12-21 69 views
0

我有一個gridview,它檢查rowDataBound event.I想根據rowDataBound.I中檢查的條件刪除一些行。嘗試將所有控件放在Panel中並隱藏該面板即,在rowDataBound事件中刪除Gridview行asp.net c#

TRY 1:

protected void grdFeatured_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     //some other codes here 
     //IMPLEMENT FILTER ACCORDING TO ABOVE 'VIS' OUTPUT 
     if (vis > 0) 
     { 
      Panel1.Visible = false; 
     } 
    } 
} 

問題:

這弄亂尋呼因爲行是隱藏但頁數發生並顯示其餘可見行的頁碼。

TRY 2:

問題:

給出了錯誤:

Specified argument was out of the range of valid values. 
Parameter name: index at gvr.Parent.Controls.RemoveAt(gvr.RowIndex); 

不想要編輯的數據源,幫助我的傢伙。

+0

您可能需要編輯您的數據源的頁面信息從數據源計算 – codingbiz

+1

請查看以下鏈接 http://stackoverflow.com/questions/592106/how-to-delete- row-from-gridview – Sumant

回答

2
if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      if (somecondition) 
      { 
       e.Row.Visible = false; 
      } 
     } 
+0

行的可見性不會影響分頁,並會混亂它。 – sajanyamaha

+0

這種方法唯一的問題是,當你採取這種方法時,你將有變化的頁面大小取決於每頁上隱藏了多少行,哈哈。 – drzounds

相關問題