Coronavirus, a large family of viruses, causes illness in both humans and animals. The novel coronavirus (COVID-19) came up in Wuhan in December 2019. This deadly COVID-19 pandemic has become very fast-spreading and currently present in several countries worldwide. The timely detection of patients who have COVID-19 is vitally important. To this end, scientists are working on different detection methods.In this paper, a grid search (GS) and pre-trained model aided convolutional neural network (CNN) model is proposed to detect COVID-19 in X-Ray images. In the proposed method, the GS method is employed to optimize the hyperparameters of CNN, which directly affects classification performance. Three pre-trained CNN models (GoogleNet, ResNet18 and ResNet50), which can be used for classification, feature extraction and transfer learning purposes were used for transfer learning in this study. The proposed method was trained using the training and validation subdatasets of the collected dataset and detail evaluations are presented according to different performance metrics. According to the experimental studies, the best results were obtained with the GS and ResNet50 aided model.