Set or obtain the selected checkboxlist value.

Source: Internet
Author: User
# Region Set or obtain the selected checkboxlist value.
/**/ /// <Summary>
/// Initialize the checked items in the checkboxlist. /// </Summary>
/// <Param name = "Checklist"> Checkboxlist </Param>
/// <Param name = "selval"> The selected value string, for example, ", 1" </Param>
/// <Param name = "separator"> The delimiter used in the value string, such as a comma in ", 1 ". </Param>
Public Static String Setchecked (checkboxlist checklist, String Selval, String Separator)
... {
Selval = Separator + Selval + Separator; // Example: ", 1"-> ", 1 ,"
For ( Int I = 0 ; I < Checklist. Items. Count; I ++ )
... {
Checklist. items [I]. Selected = False ;
String Val = Separator + Checklist. items [I]. Value + Separator;
If (Selval. indexof (VAL) ! =- 1 )
... {
Checklist. items [I]. Selected = True ;
Selval = Selval. Replace (Val, separator ); // Then, delete the selected
If (Selval = Separator) // If the last item of selval is selected, after replace, only one separator is left.
... {
Selval+ =Separator;//Add a separator
}
}
}
Selval = Selval. substring ( 1 , Selval. Length - 2 ); // Remove the added Separator
Return Selval;
}

/**/ /// <Summary>
/// Obtain the value selected in the checkboxlist.
/// </Summary>
/// <Param name = "Checklist"> Checkboxlist </Param>
/// <Param name = "separator"> Delimiter </Param>
/// <Returns> </returns>
Public Static String Getchecked (checkboxlist checklist, String Separator)
... {
String Selval = "" ;
For ( Int I = 0 ; I < Checklist. Items. Count; I ++ )
... {
If (Checklist. items [I]. Selected)
... {
Selval+ =Checklist. items [I]. Value+Separator;
}
}
Return Selval;
}
# Endregion

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.