CheckBoxList Control with SQL DataBinding

The ASP.Net CheckBoxList control also supports data binding feature that allows you to bind the data items retrieved from the SQL DataBase. In this sample we have used SQL Northwind DataBase to bind the categories table with CheckBoxList control. There are 2 ways to bind the SQL data with it, one is using in-built ASP.Net datasource server control and second is using C# code to connect and fetch the data programmatically. The SqlDataSource control provides the functionality to bind the data with CheckBoxList control by following the wizard steps. You can easily connect to the SQL Database and specify the SQL query to fetch the desired fields. The CheckBoxList control has a DataSourceID property that accepts the ID of the DataSource control used to bind the SQL Data for example ID of SQLDataSource control.

 

In this sample we have used the C# code to connect to SQL Database and fetch the categories. For checkboxlist SQL databinding using C# code we have used the DataSource property to pass the data object containing SQL records. Whether you use SqlDataSource control or C# code for SQL DataBinding you have to use the following 2 properties of CheckBoxList control to specify the text and value property for its checkbox type list items:

1. DataTextField

2. DataValueField

 

Here we have specified the "CategoryName" field as DataTextField to display the text content for checkbox list item and "CategoryID" field as DataValueField to set the back end value for each list item.

 

See the sample below to understand the output result of ASP.Net CheckBoxList control SQL DataBinding:










  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