private void ShowAllData() { showCategoryGridView.ReadOnly = true; try { DataTable dt = categoryManage.ShowAllData(); List <Category> categoryList = new List <Category>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { categoryList.Add(new Category() { SNo = i + 1, Id = Convert.ToInt32(dt.Rows[i]["Id"].ToString()), CategoryName = dt.Rows[i]["CategoryName"].ToString(), }); } showCategoryGridView.DataSource = categoryList; } } catch (Exception ex) { MessageBox.Show("" + ex); } }