public ActionResult AccessDoorEdit(string id) { Populate DropDown = new Populate(); Db_Connection dbconn = new Db_Connection(); List <SelectListItem> allowdeny_combo = new List <SelectListItem>(); allowdeny_combo = DropDown.getAllowDeny(); try { dbconn.openConnection(); string strSQL = @"SELECT LOCATION,DOOR,ACCESS FROM VWEAPON_DOOR_ACCESS WHERE ID=@ID"; SqlCommand cmd = new SqlCommand(strSQL, dbconn.DbConn); cmd.Parameters.Add("ID", SqlDbType.VarChar).Value = id; SqlDataReader dr = cmd.ExecuteReader(); mdlTrack record = new mdlTrack(); record.ID = id; if (dr.HasRows) { dr.Read(); record.ID = id; record.LOCATION = dr["LOCATION"].ToString(); record.DOOR = dr["DOOR"].ToString(); record.ACCESS = dr["ACCESS"].ToString(); } foreach (SelectListItem item in allowdeny_combo) { if (item.Text.ToUpper() == record.ACCESS.ToUpper()) { item.Selected = true; } } ViewData["access"] = allowdeny_combo; return(PartialView(record)); } finally { dbconn.closeConnection(); } }