private void btnSave_Click(object sender, EventArgs e) { try { if (grdDetails.Rows.Count == 0) { ENUtils.ShowMessage("Required : Fares"); return; } int FareId = ddlVehicleType.SelectedValue.ToInt(); if (FareId == 0) { ENUtils.ShowMessage("Required : Vehicle Type"); return; } foreach (var item in grdDetails.Rows) { //int FareId = ddlVehicleType.SelectedValue.ToInt();//item.Cells[""].Value.ToInt(); int originid = item.Cells["FROMLOCATIONID"].Value.ToInt(); int destinationid = item.Cells["TOLOCATIONID"].Value.ToInt(); decimal fare = item.Cells["FARE"].Value.ToDecimal(); int originlocationtypeid = item.Cells["FROMLOCTYPEID"].Value.ToInt(); int destinationlocationtypeid = item.Cells["TOLOCTYPEID"].Value.ToInt(); using (TaxiDataContext db = new TaxiDataContext()) { db.stp_AddNewFare_ChargesDetails(FareId, originid, destinationid, fare, originlocationtypeid, destinationlocationtypeid, null, null, null, AppVars.LoginObj.LuserId.ToInt()); } } General.RefreshListWithoutSelected <frmFaresList>("frmFaresList1"); this.Close(); } catch (Exception ex) { ENUtils.ShowMessage("Fare already exist of this Vehicle type"); } }