Populate CheckBoxList Control Items Dynamically

You can also populate the ASP.Net CheckBoxList control items dynamically using C# code. The Items collection property of checkboxlist control provides the access to its Add method that allows you to add new list items programmatically. The Add method has two overloaded versions that accept different types of parameters to insert a new list item. The first type of overloaded Add method accepts the ListItem class object whereas second overloaded method accepts a string type parameter that adds the list item directly at the end of Items collection of checkboxlist control.


In the sample below we have used the first overloaded Add function that accepts the object of ListItem class. For populating the Checkboxlist control using ListItem class object you have to initialize the object using its one of the overloaded constructor. Here we have used the following overloaded constructor of ListItem class to create the list items for checkboxlist control:

new ListItem( string text, string value );


The above C# code generates a list item with its specific text label and back end value attribute. We have also followed the same pattern in the sample below to populate the checkboxlist by specifying the values for text and value properties to add the list items. You can specify the values in the textbox controls and click the button control to add the list item dynamically.


Now try the sample below to understand the functionality to populate the ASP.Net CheckBoxList control items dynamically:

List Item Text:
List Item Value:
  1. Adrotator Control Using XML File
  2. CheckBox Control Sample
  3. FileUpload File Type Filter using JavaScript
  4. LinkButton Control Click Event
  5. RadioButton Control Sample
  6. RadioButton Control Checked and GroupName Property
  7. LinkButton Control Command Event
  8. HiddenField Control
  9. CheckBox Checked Property
  10. Adrotator Control using SqlDataSource
  11. BulletedList Control
  12. CheckBox AutoPostBack Property
  13. HiddenField Control OnValueChanged Event
  14. LinkButton OnClientClick Property
  15. RadioButton Control AutoPostBack Property
  16. RadioButton Control OnCheckedChanged Event
  17. LinkButton JavaScript Confirm Message Box
  18. HyperLink Control Sample
  19. CheckBox OnCheckedChanged Event
  20. BulletedList Control using DisplayMode
  21. BulletedList Control using SqlDataSource
  22. CheckBox Control JavaScript Validation
  23. HyperLink Control NavigateUrl Property
  24. LinkButton JavaScript Alert Box
  25. RadioButtonList Control Sample
  26. RadioButtonList Control Layout Properties
  27. LinkButton PostBackUrl Property
  28. HyperLink Control Target Property
  29. CheckBox Control Select All Using PostBack in C#
  30. BulletedList Control with Click Event
  31. Button Control
  32. CheckBox Control Check All Using JavaScript
  33. HyperLink Control ImageUrl Property
  34. Multiple LinkButtons Single Command Event Handler
  35. RadioButtonList Control OnSelectedIndexChanged Event
  36. RadioButtonList Control with SQL DataBinding
  37. ListBox Control Sample
  38. HyperLink Control OnClick Event
  39. CheckBoxList Control Sample
  40. Button Click Event
  41. Button Command Event
  42. CheckBoxList Control Layout Properties
  43. HyperLink Control Open in New Window
  44. ListBox Control AutoPostBack Property
  45. Populate RadioButtonList Control Items Dynamically
  46. TextBox Control Text Property
  47. ListBox Control OnSelectedIndexChanged Event
  48. Image Control Sample
  49. CheckBoxList Control OnSelectedIndexChanged Event
  50. Button OnClientClick Property
  51. Button Confirm Message Box
  52. CheckBoxList Control with SQL DataBinding
  53. Image Control ImageAlign Property
  54. ListBox Control SelectionMode Property
  55. TextBox Control TextMode Property
  56. TextBox Control OnTextChanged Event
  57. ListBox Control with SQL DataBinding
  58. ImageButton Control Sample
  59. CheckBoxList Control Selected Items
  60. Button Alert Message Box
  61. Button UseSubmitBehavior Property
  62. Populate CheckBoxList Control Items Dynamically
  63. ImageButton OnClick Event
  64. ListBox Control Get Multiple Selected Items
  65. XML Control with DocumentSource and TransformSource Property
  66. Populate ListBox Items Dynamically
  67. ImageButton OnCommand Event
  68. CheckBoxList Control JavaScript Validation
  69. Button PostBackUrl Property
  70. Multiple Button Controls with Single Event Handler
  71. CheckBoxList Control Select All Using PostBack in C#
  72. ImageButton OnClientClick Property
  73. ListBox Control SelectedValue Property
  74. ListBox Control SelectedIndex Property
  75. ImageButton PostBackUrl Property
  76. CheckBoxList Control Select All Using JavaScript
  77. Calendar Control
  78. Calendar Control SelectionMode Property
  79. DropDownList Control Sample
  80. Determine the Image Coordinates Using ImageButton Control
  81. Literal Control
  82. Literal Control Mode Property
  83. ImageMap Control
  84. DropDownList Control AutoPostBack Property
  85. Calendar Control SelectionChanged Event
  86. Calendar Control VisibleMonthChanged Event
  87. DropDownList Control OnSelectedIndexChanged Event
  88. ImageMap HotSpotMode Property
  89. Panel Control
  90. PlaceHolder Control
  91. ImageMap Click Event
  92. DropDownList Control with SQL DataBinding
  93. Calendar Control DayRender Event
  94. Calendar Control Date with Custom Content
  95. Populate DropDownList Items Dynamically
  96. ImageMap PostBackValue Property
  97. Label Control Text Property
  98. Setting DropDownList Default Value
  99. Calendar Control SelectedDates Dynamically
  100. Calendar Control SelectedDates using SQL Database
  101. DropDownList Control SelectedValue Property
  102. Label Control As Caption
  103. DropDownList Control SelectedIndex Property
  104. Calendar Control in Popup Window
  105. Calendar Control Customized with CSS Styles
  106. DropDownList Control JavaScript Validation
  107. DropDownList DataTextField with Multiple Columns
  108. Calendar DatePicker Control
  109. DropDownList Control with XML DataBinding