private void GetAllLocations() { try { int Id = ddlLocations.SelectedValue.ToInt(); string LocationType = ddlLocations.Text; string Error = string.Empty; if (Id == 0) { Error = "Required : Location Type"; } if (!string.IsNullOrEmpty(Error)) { ENUtils.ShowMessage(Error); return; } using (TaxiDataContext db = new TaxiDataContext()) { var list = db.stp_GetRoadLevelLocations(LocationType).Select(c => c.LocationName).AsEnumerable <string>(); // var list = db.stp_getRoadLevelLocations(LocationType).Select(c => c.LocationName).AsEnumerable<string>(); var glist = grdPostCodes.Rows.Select(c => c.Cells[COLS.AddressName].Value.ToStr()).AsEnumerable <string>(); var finalList = list.Except(glist).ToList(); if (grdPostCodes.Rows.Count == 0) { grdPostCodes.RowCount = finalList.Count; grdPostCodes.BeginUpdate(); for (int i = 0; i < finalList.Count; i++) { grdPostCodes.Rows[i].Cells[COLS.AddressName].Value = finalList[i]; //grdPostCodes.Rows[i].Cells[COLS.Select].Value = false; } grdPostCodes.EndUpdate(); } else { GridViewRowInfo row; grdPostCodes.BeginUpdate(); for (int i = 0; i < finalList.Count(); i++) { //if (grdPostCodes.Rows.Where(c => c.Cells[COLS.AddressName].Value.ToStr() == finalList[i].ToStr()).Count() == 0) //{ row = grdPostCodes.Rows.AddNew(); row.Cells[COLS.AddressName].Value = finalList[i]; // grdPostCodes.Rows[i].Cells[COLS.IsExists].Value = false; // } } grdPostCodes.EndUpdate(); } } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }