I have a GridView
and I would like to be able to select multiple rows and get the data from the column mobilenumber
and add it to list of type string. How do I that? This is what I tried but the code gives me error.
protected void Button1_Click(object sender, EventArgs e)
{
List<string> selectedRows = new List<string>();
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 < selectedRows.Count; i++)
{
this.listBox1.Items.Add(selectedRows[i]);
}
}
aspx -
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True" style="margin-left: 78px; margin-right: 0px">
<columns>
<asp:BoundField DataField="MobileNumber" HeaderText="MobileNumber" />
</columns>
</asp:GridView>