Posted By

housecor on 11/04/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

romainsauger


Check checkboxes in databound checkboxlist


 / Published in: C#
 

  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  

You need to login to post a comment.