title: How to get an Item value in asp.net gridview
body: <p>I have the following challenge. I want to get the name of the Items display on the <code>gridview</code> from the side behind...</p>
  
  <p>Pass this name as a parameter to get the count of responses for the item. This response count will be displayed on a label controls in the template fields created.</p>
  
  <p>Below is my code sample.</p>
  
  <pre><code>// Create an instance of the LogicLayer
  LogicLayer mySurvey = new LogicLayer();
  DataLayer getResponseCount = new DataLayer();
  protected void Page_Load(object sender, EventArgs e)
  {
      gvDepartments.DataSource = mySurvey.SelectDepartment();
      gvDepartments.DataBind();
      gvDepartments.Visible = true;
  
      // Declare a counter variable
      int dID = 0;
      string responses;
      string deptName;
      //string responseR;
      // Iterate though the gridView to get Dept names and response count values
      foreach (GridViewRow dept in gvDepartments.Rows) 
      {
          //Label respCount = (Label)dept.FindControl("lblResponse").Text
          // the actual way to get your row index
          int rowIndex = dept.RowIndex;
          Label respCount = (Label)gvDepartments.Rows[rowIndex].FindControl("lblResponses");
          responses = respCount.Text.ToString();
          deptName = dept.Cells[rowIndex].ToString(); // Get the department name on the gridview
          // get the responseCount for each of the departments and Map to Labels
          responses = getResponseCount.ResponseCount(deptName);
          dID++;
      }
  }
  </code></pre>
  
  <p>This is the pictural view of my grid.</p>
  
  <p><img src="https://i.stack.imgur.com/sPq0A.png" alt="enter image description here"></p>