I don't know whether this is the best solution or not but it works for me.
private void btn_export_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow dgvr in DataGridViewRow.Rows)
{
int cells = dgvr.Cells.Count;
for (int i = 0; i < cells; i++)
{
File.AppendAllText("contents.txt",dgvr.Cells[i].Value.ToString()+" ");
}
}
}