C# 隐藏某行后如何在gridview的列中显示行号(仅可见行)

C# 隐藏某行后如何在gridview的列中显示行号(仅可见行),c#,asp.net,gridview,C#,Asp.net,Gridview,这是我的前端代码: <asp:TemplateField HeaderText="NO."> <ItemTemplate ><div ID="PicCounter" style="text-align: center; color:black"><%# Container.DataItemIndex + 1 %></div></ItemTemplate&g

这是我的前端代码:

<asp:TemplateField HeaderText="NO.">
                                      <ItemTemplate ><div ID="PicCounter" style="text-align: center; color:black"><%# Container.DataItemIndex + 1 %></div></ItemTemplate>
                             </asp:TemplateField>     
 int sum = 0;
    protected void gv_Action_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                Label Action = (Label)e.Row.FindControl("ACTION");//take lable id

                if (Action.Text.ToString() == "0")
                {
                    e.Row.Visible = false;
                }
                else if (Action.Text.ToString() != "")
                {
                    sum += int.Parse(Action.Text);
                    lblTotalNoti.Text = sum.ToString();


                }



            }
        }

        catch (Exception ex)
        {
            Log.Write("gv_Action_RowDataBound() Error: " + ex.Message.ToString() + ex.StackTrace.ToString());
            ERRORMSG.Text = "gv_Action_RowDataBound() Error: " + ex.Message.ToString();

        }

    }

隐藏某些行后,我想将每个可见行的行编号放在网格视图的列中。我的问题是我隐藏的行也编号了。请帮助我,我是初学者。

我自己解决了:将此添加到后端

if (e.Row.Visible == true)
                {
                    numVisible += 1;

                    Label lblRowCounter = (Label)e.Row.FindControl("lblRowCounter");//take lable id

                    lblRowCounter.Text = numVisible.ToString();

                }

为什么不将这些行隐藏在DataTable或dataset本身中?