public String demographicfield(int fieldID,int pollID,String [] items) { var result = ""; var poll = pollRepository.GetPollByID(pollID); List<string> values = new List<string>(); IList<ParticipantFieldValue> valued = participantRepository.GetParticipantFieldByID(fieldID).fieldValues.Where(valu => (!valu.value.Equals(""))).ToList(); if (poll.isGroup) valued = valued.Where(v => v.groupd != null).ToList(); else valued = valued.Where(v => v.participant != null).ToList(); values = (from v in valued select v.value).Distinct().ToList(); bool num = true; int number; if (values.Any(v => (!int.TryParse(v, out number)))) num = false; if (num == false) { values.Sort((x, y) => string.Compare(x, y)); foreach (String value in values) { if (items != null && items.Contains(value)) result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />"; else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />"; } } else { List<int> intvalues = values.ConvertAll<int>(delegate(String i) { return int.Parse(i); }); intvalues.Sort(); foreach (int value in intvalues) { if (items != null && items.Contains(value.ToString())) result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />"; else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />"; } } return result; }