title: Select multiple rows in c# and pass data to a List?
body: <p>I have a <code>GridView</code> and  I would like to be able to select multiple rows and get the data from the column <code>mobilenumber</code> and add it to list of type string. How do  I that? This is what I tried but the code gives me error.</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      List&lt;string&gt; selectedRows = new List&lt;string&gt;();
      foreach (DataGridViewRow row in GridView1.SelectedRows)
      {
          string currentRow = string.Empty;
          foreach (DataGridViewCell cell in row.Cells)
          {
              currentRow += String.Format("{0} ", cell.FormattedValue);
          }
          selectedRows.Add(currentRow);
      }
      for (int i = 0; i &lt; selectedRows.Count; i++)
      {
          this.listBox1.Items.Add(selectedRows[i]);
      }
  }
  </code></pre>
  
  <p>aspx -</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True" style="margin-left: 78px; margin-right: 0px"&gt;
      &lt;columns&gt;
          &lt;asp:BoundField DataField="MobileNumber" HeaderText="MobileNumber" /&gt;
      &lt;/columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>