简体   繁体   English

过滤(或隐藏)Gridview行时,Asp.net / c#-> Gridview Pager无法更新

[英]Asp.net/c# -> Gridview Pager doesn't get updated when gridview rows are filtered (or hidden)

I have the below code where I have some conditions because of which I have to hide the row from showing to end user. 我在下面的代码中有一些条件,由于这些原因,我不得不隐藏向最终用户显示的行。 "ShowRow" is a boolean value that gets set in GetUnitOfMeasure function (not copied here) based on these conditions. “ ShowRow”是一个布尔值,它根据这些条件在GetUnitOfMeasure函数中设置(此处未复制)。

There are some real conditions which is forcing me to hide. 有一些现实条件迫使我躲藏起来。 I tried to include them while building data source but I have to hide it before display. 在构建数据源时,我试图将它们包括在内,但必须在显示之前将其隐藏。

Problem I am facing is the paging is not getting refreshed based on total rows shown at the end. 我面临的问题是,基于最后显示的总行,分页没有得到刷新。 For example, if I have TOTAL of 200Rows in the grid and only 2 rows needs to be shown and if these 2 rows are found in paging 3, then when page is loaded it still shows paging 1 2 3 4 and 3rd page has the valid 2 rows. 例如,如果我在网格中共有200行,并且仅需要显示2行,并且如果在分页3中找到了这2行,那么在加载页面时它仍显示分页1 2 3 4,而第3页具有有效的2行。

Please suggest.I have also used "onDataBound" against gridview (not copied here) but I just hide some columns here. 请提出建议。我还对gridview使用了“ onDataBound”(未在此处复制),但我只是在这里隐藏了一些列。

ASPX page ASPX页面

<asp:GridView ID="SearchResults" runat="Server" AutoGenerateColumns="false" EnableViewState="false"
AllowPaging="true" PageSize="50"  OnDataBound ="SearchResults_DataBound" OnRowDataBound="SearchResults_RowDataBound">
<RowStyle CssClass="EvenRow" />
<AlternatingRowStyle CssClass="OddRow" />
<Columns>
    <asp:TemplateField meta:resourceKey="UmSellField">
        <ItemStyle CssClass="alpha" />
        <HeaderStyle CssClass="alpha" />
        <ItemTemplate>
            <asp:Label ID="UmSellLabel" runat="server" EnableViewState="false" Text='<%# GetUnitOfMeasure(Container.DataItem,false) %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

codebehind 代码隐藏

protected void SearchResults_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType.Equals(DataControlRowType.DataRow))
    {
        e.Row.Visible = showRow;
        e.Row.Cells[0].Visible = showRow;
    }
}

我不确定它是否会工作,但是也许您尝试设置e.Row.Enabled = showRow以及设置其可见性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM