I have a dropdown in which datas are binding from database. its works fine in which I need to display one particular item a first value in the dropdown. For example dropdown with arun,siva,kumar in which siva must be at the first place note three datas coming from database. View:
@using (Html.BeginForm()) {
<fieldset>
<legend>Multi-Select Demo</legend>
<div class="editor-field">
@Html.DropDownList("FirstName", Model.SelectNameList);
)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
Controller
public ActionResult List()
{
SqlConnection conn = new SqlConnection(con);
Patient model = new Patient();
List<Patient> objUserDetails = new List<Patient>();
DataTable dt = new DataTable();
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Patients", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
var studentCount = dt.Rows.Count;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Patient userinfo = new Patient();
userinfo.FirstName = dt.Rows[i]["FirstName"].ToString();
userinfo.PatientId = Convert.ToInt16(dt.Rows[i]["PatientId"]);
objUserDetails.Add(userinfo);
}
}
model.SelectNameList = new SelectList(objUserDetails, "PatientId", "FirstName");
return View(model);
}
I want the sixth data of my list as first data in dropdown