title: Automatically adding a row to a gridview when certain conditions are present
body: <p>I need to add a row to a gridview which has AutoGenerateColumns="true". Here is the trick though. The SQL query is written in such way (using pivot) that it returns records in groups of three as depicted below:</p>
  
  <pre><code>Repair Code Repair Code Entries 6/1/2012    7/1/2012    8/1/2012    9/1/2012
  00000A  Critical Down Time          1       
  00000A  Critical Outage             1       
  00000A  Total Repair Time          65       
  00000B  Critical Down Time                                              6
  00000B  Critical Outage                                                 3
  00000B  Total Repair Time                                              90
  00000C  Critical Down Time          1                      5    
  00000C  Critical Outage             1                      5    
  00000C  Total Repair Time          30                    240    
  00000D  Critical Down Time                                 2     
  00000E  Critical Down Time                                 1    
  00000G  Critical Down Time                                 1    
  00000M  Critical Down Time          1                      3    
  00000M  Critical Outage             1                      3    
  00000M  Total Repair Time          60                    180    
  </code></pre>
  
  <p>I need to add a blank row between 00000A and XYXYXY. The GridView is populated from a bll class using a DataTable. I'm utilizing the OnRowCreated method to modify the column headers and OnRowDataBound to format the information in the cell. </p>
  
  <p>I thought I could add a row in eihter of the two event methods but it seems to me that it would be too late in the cycle. I'm I right?</p>
  
  <p>I've come across various posts like <a href="https://stackoverflow.com/questions/10982744/add-row-to-asp-net-gridview">this one</a> and <a href="http://www.codeproject.com/Articles/467788/Dynamically-adding-and-deleting-rows-from-ASP-NET" rel="nofollow noreferrer">this one</a> but they all going about it in a diferrent way such as a button click event. </p>
  
  <p>In my case the only constant that I can depend on are the presence or absense of the three categories: the down time, repair time and total. There are instances where I only have one or two of the three categories and this is where I need to insert a row with corresponding missing category.</p>
  
  <p>Any suggestions how to to go about it?</p>
  
  <p>Thanks,</p>
  
  <p>R.</p>
  
  <p>UPDATE: I've updated the output from the query above. As you see in the lower half "Critical Down Time" is repeaded 4 times so I need to intercept the data and add "Critical Outage", "Total Repair Time", and a blank row as separator.</p>