title: Loop through GridViewRow method
body: <p>Afternoon everyone, I may be having a real dumb moment here but I have this section of code:</p>
  
  <pre><code> var playerCount = 0;
   foreach (GridViewRow row in GridAttendees.Rows)
     {
         playerCount++;
     }
         LabelAttendees.Text = string.Format("Attending Players ({0})", playerCount);
  </code></pre>
  
  <p>It simply loops through a Gridview and counts the rows, updating the total. My first thought was to add it to the Page_Load event, however there are several functions on that page that can cause the Attendee List to increase.</p>
  
  <p>My first thought was to add this snippet to all other events that change the attendee numbers, but we all know that we are duplicating code this way.</p>
  
  <p>Instead I thought about adding it to my class, rather than the .aspx.cs page, as a method 'updateAttendeeCount()', and calling that instead.</p>
  
  <p>How do I access 'GridRowView' in the class? And how do I access the GridView itself? By using the findcontrol?</p>
  
  <p>Or is there another way to look at this (without having the page refresh/reload each time).</p>
  
  <p>cheers guys
  Jason</p>