繁体   English   中英

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

[英]How to display row number(only visible row) in a column of gridview after hiding certain row

这是我的前端代码:

<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();

                }

暂无
暂无

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

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