Use of checklistbox and checklistbox

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.