2017-07-13 116 views
0

后显示在GridView中的列行数(仅可见行)这是我的前端代码:如何隐藏某一行

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

     } 

    } 

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

+1

? – Krishna

回答

0

我自己解决:你为什么不隐藏在数据表或数据集本身的列一下添加到后端

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

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

        lblRowCounter.Text = numVisible.ToString(); 

       } 
+0

请使用您问题上的编辑链接添加其他信息。后回答按钮应该只用于问题的完整答案。 - [来自评论](/ review/low-quality-posts/16714051) – kdopen