title: Want to get total of same string values in a column of gridview
body: <p>There is checkbox column in the gridview from which string value "P" is getting on checked. So, I want to calculate all rows of this column having same "P" values. I tried below code:</p>
  
  <pre><code>int sumP = 0;
  public void countpresent()  //To count all Present Students in the gridview
  {
      for (int i = 0; i &lt; (dgvAttendance.Rows.Count-1); i++)
      {
          if (dgvAttendance.Rows[i].Cells["Present"].Value.ToString() == "P")
          {
              sumP += 1;
          }
      }
      lblPresent.Text = sumP.ToString();
  }
  </code></pre>
  
  <p>it is working for all the sting "P" but when it shows value null, it throws an exception "Object reference notset to an instance of an object". In the exception detail it is showing "NullReferenceException". 
  Please any one suggest something to help</p>