title: How to repeat the header template in gridview?
body: <p>In asp.net, I am using gridview for displaying the data. In gridview I am displaying 300 records at a time. Now I want to display the header template after every 30 rows in gridview is it possible?
  I write like this in gridview_rowdatabound.</p>
  
  <pre><code>     GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);  
          TableCell cell = new TableCell();
          cell.Controls.Add(new Label { Text = "Header" }); //as needed
          row.Cells.Add(cell);
          cell = new TableCell();
          cell.Controls.Add(new Label { Text = "Name" }); //as needed
          row.Cells.Add(cell);
  
          cell = new TableCell();
          cell.Controls.Add(new Label { Text = "add" }); //as needed
          row.Cells.Add(cell);
  
          cell = new TableCell();
          cell.Controls.Add(new Label { Text = "Nice" }); //as needed
          row.Cells.Add(cell);
  
          Table tbl = (e.Row.Parent as Table); 
          tbl.Controls.AddAt(e.Row.RowIndex * 3 + 1, row);   
  </code></pre>
  
  <p>when I place  tbl.Controls.AddAt(e.Row.RowIndex * 2 + 1, row);   it is working when I place more than 2 like 3, 4 like this, then it is throing error.</p>
  
  <p>I solve the problem: </p>
  
  <pre><code>    if (e.Row.RowType == DataControlRowType.DataRow) 
         {
          if (e.Row.RowIndex == 0)
          {
              ViewState["i"] = e.Row.RowIndex;
          }
  
          if (Convert.ToInt32(ViewState["i"].ToString()) == e.Row.RowIndex)
          {
              GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);
              TableCell cell = new TableCell();
              cell.BackColor = System.Drawing.Color.BurlyWood;
              cell.Controls.Add(new Label { Text = "header" }); //as needed              
              row.Cells.Add(cell);
  
              cell = new TableCell();
              cell.BackColor = System.Drawing.Color.BurlyWood;
              cell.Controls.Add(new Label { Text = "Name" }); //as needed
              row.Cells.Add(cell);
  
              cell = new TableCell();
              cell.BackColor = System.Drawing.Color.BurlyWood;
              cell.Controls.Add(new Label { Text = "add" }); //as needed
              row.Cells.Add(cell);
  
              cell = new TableCell();
              cell.BackColor = System.Drawing.Color.BurlyWood;
              cell.Controls.Add(new Label { Text = "Nice" }); //as needed
              row.Cells.Add(cell);
              int cnt = Convert.ToInt32(ViewState["i"].ToString());
  
              Table tbl = (e.Row.Parent as Table);
  
              //tbl.Controls.AddAt(e.Row.RowIndex * cnt , row);
               tbl.Controls.AddAt(e.Row.RowIndex, row);               
  
              cnt = cnt + 4;
              ViewState["i"] = cnt.ToString();
          }
      } 
  </code></pre>