In the project, when you set the assessment object. If you have set an assessment object, select the check box for the set assessment object. If no value is set, you can select the check object to use CheckboxListbox, where CheckboxListbox is used. Here is a brief introduction.
I. attributes and events 1. AutoPostBack attributes: Used to set whether to automatically send the checkboxList control to the server when it is clicked. True indicates delivery; False (default) indicates not delivery.
2. DataSource attribute: used to specify the data source of the fill list control.
3. DataTextField attribute: Specifies a field in DataSource. The value of this field corresponds to the Text attribute of the list item.
4. DataValueField attribute: Specifies a field in DataSource. The field Value corresponds to the Value attribute of the list item.
5. Items properties: indicates the set of options in the check box list. For example, CheckBoxList1.Items (I) indicates the I option, and I starts from 0.
Each option has the following three basic attributes:
Text attribute: indicates the Text of each option.
Value Attribute: The option Value of each option.
Selected attribute: indicates whether the Selected option is Selected.
6. RepeatColumns attribute: used to specify the number of columns that the option occupies in the CheckBoxList control. The default value is 0, indicating any number of columns.
7. RepeatDirection attribute: used to specify the display direction of the CheckBoxList control. Vertical, the list items are displayed in the form of column precedence; Horizontal, column items are displayed in the form of row precedence.
8. RepeatLayout attribute: used to set the arrangement of options. Table (default) is displayed in the Table structure. When the attribute value is Flow, it is not displayed in the Table structure.
9. SelectedIndex attribute: used to obtain or set the index value of the lowest sequence number of the selected item in the list. If only one option in the list control is selected, this attribute indicates the index value of the selected item.
10. SelectedItem attribute: used to obtain the selected item with the smallest index value in the list control. If only one option is selected in the list, this attribute indicates the selected item. You can obtain the Text and Value attribute values of the selected item through this attribute.
11: SelectedIndexchanged event: an event is triggered when you select any check boxes in the list.
II. Specific instance HTML code:
<Div title = "Development Zone (Park)" style = "padding: 10px"> <asp: updatePanel ID = "UpdatePanel3" runat = "server"> <ContentTemplate> <div> <asp: button ID = "cmdSelectedDevelopment" runat = "server" Text = "Submit" ToolTip = "Submit the selected assessment object" OnClick = "cmdSelectedDevelopment_Click" Style = "height: 20px "/> </div> <asp: CheckBox ID =" SelectAll "runat =" server "Text =" select all "OnClick =" selectAll ('cbldevelopmentinfo ') "/> <asp: CheckBoxList ID =" cblDevelopmentInfo "RepeatDirection =" Horizontal "RepeatColumns =" 5 "runat =" server "> </asp: checkBoxList> </ContentTemplate> </asp: UpdatePanel> </div>
Select All JS files
<% -- Select all checkboxlist -- %> <script type = "text/javascript"> function selectAll (searchName) {var aa = document. getElementsByTagName ("input"); for (var I = 0; I <aa. length; I ++) {if (aa [I]. type = 'checkbox' & aa [I]. name. indexOf (searchName)>-1) {aa [I]. checked = event. srcElement. checked ;}}</script>
C #
Code:
// When the page is loaded for the first time, bind the data if (! IsPostBack = true) {this. cblDevelopmentInfo. dataSource = development. getDevelopmentInfo (); this. cblDevelopmentInfo. dataTextField = "DepartmentName"; // The value displayed on the foreground, that is, the value displayed in the CheckBoxList. this. cblDevelopmentInfo. dataValueField = "CityID"; // this value is invisible directly on the page, but this can be seen in the source code. cblDevelopmentInfo. dataBind () ;}// perform database operations on the selected Checboxlist // obtain the selected check object DataSet dtCheckedDepartInfo = development. getList ("Checked = 'yes' and Status = 'active'"); // The External Loop is to obtain the selected evaluation object for (int I = 0; I <dtCheckedDepartInfo. tables [0]. rows. count; I ++) {// selected evaluation object field string strCheckedCity = dtCheckedDepartInfo. tables [0]. rows [I] ["CityID"]. toString (); for (int j = 0; j <cblDevelopmentInfo. items. count; j ++) {// all the assessment objects string strUnCheckedCity = cblDevelopmentInfo. items [j]. value. toString (); if (strCheckedCity = strUnCheckedCity) {cblDevelopmentInfo. items [j]. selected = true; break ;}} update the Selected item to the database # click the submit button in the region Development Zone Tab to submit the Selected evaluation object to the database protected void cmdSelectedDevelopment_Click (object sender, eventArgs e) {EvaluationSystem. model. developmentBaseEntity developmententity = new DevelopmentBaseEntity (); // instantiate the corresponding object class EvaluationSystem. BLL. developmentBaseBLL developmentrecord = new DevelopmentBaseBLL (); // instantiate the corresponding B-layer business logic developmentrecord. updateNoSelected (); for (int I = 0; I <this. cblDevelopmentInfo. items. count; I ++) // Through the loop {if (this. cblDevelopmentInfo. items [I]. selected) // obtain the Selected items in the control {developmententity. cityID = Convert. toString (this. cblDevelopmentInfo. items [I]. value); // obtain the Object ID if (developmentrecord. updateChecked (developmententity. cityID) = true) // if it is successfully added, the {ScriptManager. registerClientScriptBlock (UpdatePanel3, this. getType (), "click", "alert ('Assessment object set successfully ')", true); this. cblDevelopmentInfo. items [I]. selected = true; SelectAll. checked = false;} else {ScriptManager. registerClientScriptBlock (UpdatePanel3, this. getType (), "click", "alert ('failed to set the assessment object, please contact the system Postmaster ')", true) ;}}# endregion
Iii. Summary
Here, the Checkboxlist is combined with the UpdataPannel in Asp.net to implement a small business function in the project. If you think about it, it is nothing more than the basic attributes of the control. In addition, JS operations on html are combined with the loop structure to achieve the requirements.