title: Remove Gridview row in rowDataBound event asp.net c#
body: <p>I have a gridview which checks some values on <code>rowDataBound</code> event.I want to remove some rows based on conditions checked in rowDataBound.I tried putting all controls in a Panel and hiding that panel ie,</p>
  
  <p><strong>TRY 1 :</strong></p>
  
  <pre><code>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 &gt; 0)
          {
              Panel1.Visible = false;
          }
      }
  }
  </code></pre>
  
  <p><strong>PROBLEM :</strong></p>
  
  <p>This messes up the paging since rows are hidden but page count occurs and shows page numbers for the remaining visible rows.</p>
  
  <p><strong>TRY 2 :</strong></p>
  
  <pre><code>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 &gt; 0)
          {
              gvr.Parent.Controls.RemoveAt(gvr.RowIndex);
          }
      }
  }
  </code></pre>
  
  <p><strong>PROBLEM :</strong></p>
  
  <p>gives error :</p>
  
  <blockquote>
  <pre><code>Specified argument was out of the range of valid values.
  Parameter name: index at gvr.Parent.Controls.RemoveAt(gvr.RowIndex);
  </code></pre>
  </blockquote>
  
  <p>dont want to edit datasource, help me out guys .</p>