Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your method should return <code>List&lt;SelectListItem&gt;</code> instead of <code>List&lt;SelectList&gt;</code>:</p> <pre><code>public List&lt;SelectListItem&gt; SelectDoctoronEdit(int id) { Gema_Doctor[] doctorList; doctorList = gema_Doctor.GetDoctor().ToArray(); List&lt;Gema_Doctor&gt; listDoctor = new List&lt;Gema_Doctor&gt;(doctorList); List&lt;SelectListItem&gt; dropItems = new List&lt;SelectListItem&gt;(); RDM_Patient patientsSelect = rdm_Patient.GetPatient().First(c =&gt; c.PatientID == id); dropItems.Add(new SelectListItem { Text = "--Select--", Value = "" }); foreach (Gema_Doctor doctorValues in listDoctor) { RDM_Patient patients = rdm_Patient.GetPatient().First(c =&gt; c.PatientID == id); if (patients.DoctorID == doctorValues.Dr_Id) { dropItems.Add(new SelectListItem { Text = doctorValues.Dr_Name, Value = doctorValues.Dr_Id.ToString(), Selected = true }); } else { dropItems.Add(new SelectListItem { Text = doctorValues.Dr_Name, Value = doctorValues.Dr_Id.ToString(), Selected = false }); } } return new SelectList(dropItems, "Value", "Text", patientsSelect.DoctorID); } </code></pre> <p>or if you prefer a <code>SelectList</code> directly:</p> <pre><code>public SelectList SelectDoctoronEdit(int id) { Gema_Doctor[] doctorList; doctorList = gema_Doctor.GetDoctor().ToArray(); List&lt;Gema_Doctor&gt; listDoctor = new List&lt;Gema_Doctor&gt;(doctorList); List&lt;SelectListItem&gt; dropItems = new List&lt;SelectListItem&gt;(); RDM_Patient patientsSelect = rdm_Patient.GetPatient().First(c =&gt; c.PatientID == id); dropItems.Add(new SelectListItem { Text = "--Select--", Value = "" }); foreach (Gema_Doctor doctorValues in listDoctor) { RDM_Patient patients = rdm_Patient.GetPatient().First(c =&gt; c.PatientID == id); if (patients.DoctorID == doctorValues.Dr_Id) { dropItems.Add(new SelectListItem { Text = doctorValues.Dr_Name, Value = doctorValues.Dr_Id.ToString(), Selected = true }); } else { dropItems.Add(new SelectListItem { Text = doctorValues.Dr_Name, Value = doctorValues.Dr_Id.ToString(), Selected = false }); } } return dropItems; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload