private void MatchExcelAndDbColumns() { foreach (GridViewRow row in dgvColumns.Rows) { string excelCol = row.Cells[0].Text.Trim().ToUpper(); IQueryable <ListItem> dbColItems = (row.Cells[1].FindControl("ItemDropDown") as DropDownList).Items.Cast <ListItem>().AsQueryable() as IQueryable <ListItem>; string[] dbCols = dbColItems.Where(i => !i.Value.Contains("IGNORE")).Select(i => i.Value).ToArray(); string bestMatch = LevenshteinDistance.FindBestMatch(excelCol, dbCols); ListItem bestItem = (row.Cells[1].FindControl("ItemDropDown") as DropDownList).Items.FindByValue(bestMatch); if (bestItem != null) { bestItem.Selected = true; } } }