Use of checklistbox and checklistbox
Public class CheckListboxHelper {# region binds a data source to checklistbox /// <summary> /// bind a data source to checklistbox /// </summary> /// <typeparam name = "T"> Data Source Type </typeparam> /// <param name = "checklistbox"> checklistbox object </param> /// <param name = "list"> data source </param> /// <param name = "texfield"> display value field name </param> /// <param name = "valuefield"> value field name </param> public void CheckListboxDatabind <T> (CheckBoxList checklistbox, list <T> list, string texfield, string valuefield) {checklistbox. dataSource = list; checklistbox. dataTextField = texfield; checklistbox. dataValueField = valuefield; checklistbox. dataBind ();} # endregion # region obtain the selected value of checklistbox /// <summary> /// obtain the selected value of checklistbox /// </summary> /// <param name = "checklistbox"> checklistbox object </param> /// <returns> string </returns> public string GetChecklistvalue (CheckBoxList checklistbox) {string listvalue = ""; for (int I = 0; I <checklistbox. items. count; I ++) {if (checklistbox. items [I]. selected) {listvalue = listvalue + checklistbox. items [I]. value + "," ;}} listvalue = new StringHelper (). replaceLastchar (listvalue, ","); return listvalue;} # endregion # region sets the public void SetCheckListBoxChecked (CheckBoxList checklistbox, string checkvale) {string [] checkstrs; checkstrs = checkvale. split (','); for (int I = 0; I <checklistbox. items. count; I ++) {for (int j = 0; j <checkstrs. length; j ++) {if (checklistbox. items [I]. value = checkstrs [j]) {checklistbox. items [I]. selected = true; break ;}}# endregion # region set checkboxlist all public void SetCheckListBoxAllChecked (CheckBox controlChecklistbox, CheckBoxList checklistbox) {for (int I = 0; I <checklistbox. items. count; I ++) {checklistbox. items [I]. selected = controlChecklistbox. checked ;}# endregion}
Today, checklistboxbox is used to encapsulate common methods. It can be used by friends who need it. It is also a record of what they write.