簡體   English   中英

刪除rowDataBound事件中的Gridview行asp.net c#

[英]Remove Gridview row in rowDataBound event asp.net c#

我有一個gridview,它檢查rowDataBound事件上的一些值。 rowDataBound想根據rowDataBound中檢查的條件刪除一些行。我嘗試將所有控件放在一個Panel中並隱藏該面板即,

嘗試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;
        }
    }
}

問題:

由於行被隱藏但頁面計數發生並且顯示剩余可見行的頁碼,這會使分頁混亂。

嘗試2:

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

問題:

給出錯誤:

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

不想編輯數據源,幫幫我們。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM