繁体   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