/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
cblTeamMembers.DataSource = from t in db.TeamMembers orderby t.Name select t; cblTeamMembers.DataTextField = "Name"; cblTeamMembers.DataValueField = "TeamMemberID"; cblTeamMembers.DataBind(); if (Request["ID"] != null) //so editing { courtCase = GetCase(); if (courtCase == null) throw new HttpException(404, "file not found"); //so the ID requested wasn't found. Redirect to 404. txtName.Text = courtCase.caseName; List<int> currentTeamMembers = (from t in db.CaseTeamMembers where t.CaseID == Convert.ToInt32(Request["ID"]) select t.CaseID).ToList<int>(); foreach (ListItem li in cblTeamMembers.Items) { li.Selected = (currentTeamMembers.Contains(Convert.ToInt32(li.Value))); }