Check checkboxes in databound checkboxlist


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. cblTeamMembers.DataSource = from t in db.TeamMembers
  2. orderby t.Name
  3. select t;
  4. cblTeamMembers.DataTextField = "Name";
  5. cblTeamMembers.DataValueField = "TeamMemberID";
  6. cblTeamMembers.DataBind();
  7.  
  8. if (Request["ID"] != null) //so editing
  9. {
  10. courtCase = GetCase();
  11. if (courtCase == null) throw new HttpException(404, "file not found"); //so the ID requested wasn't found. Redirect to 404.
  12.  
  13. txtName.Text = courtCase.caseName;
  14. cbActive.Checked = (courtCase.ActiveCase == "Y");
  15.  
  16. List<int> currentTeamMembers = (from t in db.CaseTeamMembers
  17. where t.CaseID == Convert.ToInt32(Request["ID"])
  18. select t.CaseID).ToList<int>();
  19.  
  20. foreach (ListItem li in cblTeamMembers.Items)
  21. {
  22. li.Selected = (currentTeamMembers.Contains(Convert.ToInt32(li.Value)));
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.