ASP.NET WEBFORM Components CheckBoxList Programming

xiaoxiao2021-03-06  116

Author: Ma Jinhu from: yesky

The Checkbox Selection component is a regular component in a program. This component is used in programming, generally not only one, often appears in the form of multiple such components. In the ASP.NET page, if you want to use multiple Checkbox components, in addition to adding multiple Checkbox components in the page, there is a relatively convenient way to use the CheckBoxList component. The CheckBoxList component is composed of a set of Checkbox components. Checkbox in this component is in the form of an entry, and there is an index number for each checkbox in the checkboxlist component, which is easier in the program. Treatment. At this time, you may have to ask, this is not a lot of this one, since there is a checkbox component, what is the CheckBoxList component? This is because in the process of programming, handling the CheckboxList component is often more prone to more and clearly more and more. Examples are as follows: Assume that there is a checkboxlist component and there are ten Checkbox components, and this CheckBoxList component is made up of this ten Checkbox components. In order to detect which of these ten Checkbox components have been selected, if the Checkbox component selected in the program requires the following code:

IF (c1. Checked) {} ​​f (c2. check) {} .... if (c10. Checked) {}

But if you use the CheckBoxList component in the program, you only need the following lines of code:

For (int i = 0; i

Note: Where C1-C10 is the Checkbox component, CHK is the CheckBoxList component, which is used by CheckBoxList components, which is indeed clearer in programming, and more concise. And as long as you have the usage of the CheckboxList component, the Usage of the Checkbox component will be roughly.

One. How to create a CheckBoxList component:

First check box Second Check Box Third check box ..... Note: You can join several check boxes

Add the above statement to the ASP.NET page, you can generate a CheckBoxList component named "C1".

two. The properties that are often used in the checkboxlist component:

I> .textalign attribute: Take the value: Left, Right. If the value of TextAlign is Left, the text of the check box in the checkboxlist component is on the left side of the box, the same reason If the value of TextAlign is Right, check the words of the check box on the right of the box. II> .selected attribute: is a Boolean, determines whether the checkbox in the component is selected.

III> .repeatcolumns attribute: There are several check boxes in the checkboxlist component, which is primarily to set these check boxes to the bottom to display.

IV> .repeAtDirection property: This property can be: Vertical, Horizontal. When the RepeatColumns property is set, it is set to set this property to arrange each check box in the component. details as follows:

Assume that the CheckBoxList component has four check boxes, and the RepeatColumns property is 2.

(1). If repeatdirection = veriTical, check the box in the page is as follows:

Check box 01 check box 03

Check box 02 check box 04

(2). If Repeatorction = Horizontal, check the display of the box in the page is as follows:

Check box 01 check box 02

Check box 03 check box 04

V> .count properties: Returns how much check boxes in the CheckBoxList component.

three. Methods often use in the CheckBoxList component:

(1). Add a check box in the component, the syntax is as follows:

CHKLIST. ITEMS. Add (New ListItem (, ))

(2). Access the check box in the component, the syntax is as follows:

CHKList. Items []

(3). Delete check boxes in the component, the syntax is as follows:

CHKLIST. Items. Remove ()

four. An example introduces the method of use of the checkboxlist component: (1). How to determine which checkboxes in the component:

In the program, it is done by processing the Selected attribute and count attributes, as follows:

For (int i = 0; i "; }

(2). How to set the appearance layout of the CheckBoxList component:

The checkboxlist component has a relatively large attribute to set its appearance. In the program introduced in this article, it is mainly to set the appearance layout of the component in four aspects: the sequence of texts in the checkbox in the component and the arrangement of the box Each check box layout in the component, the number of lines arranged in each check box in each check box in the component, and the specific program code is as follows:

Switch (CBOALIGN. SELECTEDINDEX) {casual = textalign. Left; break; case 1: chklist.... // Component in each check box layout Switch (CBOREPEATLAYOUT. SELECTEDINDEX) {case 0: chklist. RepeatLayout = RepeatLayout. Table; Break; Case 1: chklist. REPEATLAYOUT = RepeatLAYout. Flow; Break;} // Component in each check box arrangement a direction switch (cboRepeatDirection SelectedIndex.) {case 0: ChkList RepeatDirection = RepeatDirection Vertical; break; case 1:.... ChkList RepeatDirection = RepeatDirection Horizontal; break;} // number of rows are arranged in each component of the checkbox try {int cols = int. parse (txtrepeatcols.text); chklist. REPEATCOLUMNS = cols;} catch (exception) {}. Sino - Source Program Code (Check.aspx) and Executive Interface:

The figure below is to generate the interface: Check.aspx, the generated interface:

Check.aspx source code code is as follows:

<% @ Page language = "c #"%> checkboxlist component presentation </ title> <script runat = "server"> protected void button_click (object sender, eventargs e) {// component Switch (CBOALIGN. SELECTEDINDEX) {casual = textalign. Left; break;} // component respective check boxes layout switch (cboRepeatLayout SelectedIndex.) {case 0: ChkList RepeatLayout = RepeatLayout Table; break; case 1:.... ChkList RepeatLayout = RepeatLayout Flow; break;} // check each component block arrangement direction switch ( . cboRepeatDirection SelectedIndex) {. case 0: ChkList RepeatDirection = RepeatDirection Vertical; break; case 1:.. ChkList RepeatDirection = RepeatDirection Horizontal; break;.} // number of rows are arranged in each component of the checkbox try {int cols = int. Parse (txtrepeatcols.text); chklist. RepeatColumns = cols;} catch (exception) {} lblresult. Text = ""; for (int i = 0; i <c HKList. items. Count; i ) {if (chklist. items [i]. SELECTED) {lblresult. Text = chklist. items [i] .text "<br>";}}} </ script> </ Head> <body> <form runat = "server"> <h1 align = center> checkboxlist component presentation </ h1> <Table> <TR> <TD> components in the text arrangement location: </ td> <td> <Ask: DropDownList ID =</p> <p>CBOALIGN RUNAT = "Server"> <asp: listitem> 左 </ asp: listitem> <ask: listitem> Home </ asp: listitem> </ asp: dropdownload> </ td> </ tr> <tr> < TD> components: </ td> <td> <ask: DropDownload Runat = CBOREPEATLAYOUT RUNAT = "Server"> <asp: listitem> Table </ asp: listitem> <ask: ListItem> Compact </ ASP: ListItem> </ asp: DropdownList> </ td> </ tr> <tr> <TD> Components Each entry Arrange direction: </ td> <TD> <asp: DropdownList ID = CBOREPEATDIRECTION RUNAT = "Server" > <Asp: listitem> horizontal direction </ asp: listitem> <ask: ListItem> Vertical direction </ asp: listitem> </ asp: dropdownloadList> </ td> </ tr> <tr> <TD> components in each Entries: </ td> <TD> <asp: textbox id = "txtrepeatcols" runat = "server" /> </ td> </ tr> </ table> <br> Please select what you need to learn Computer Language Type: <br> <asp: checkboxlist id = "chklist" repekboxlist = horizontal runat = "server"> <ask: ListItem> Visual C .NET </ ask: ListItem> <ask: ListItem> Visual C # <</p> <p>/ asp: listitem> <ask: listitem> VB.NET </ ask: listitem> <ask: listitem> jscript.net </ ask: listItem> <ask: ListItem> Visual J # </ asp: listItem> </ asp: CheckBoxList> <br> <asp: button text = "Submit" runat = "server" onclick = "button_click" /> <h1> <font color = red> The computer language type you choose is: </ font> </ h1 > <Asp: label id = lblresult runat = "server" /> </ form> </ body> </ html> six. to sum up:</p> <p>In fact, CheckBoxList components are also a server-side component. This article describes some of the key attributes and methods in the CheckBoxList component, and how to perform programming related to checkboxlist components in the ASP.NET page through a comparison example, in fact, for another more important components - CHECKBOX Say, there are many similarities to master the use of CheckBoxList components, and also master the use of Checkbox components.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-98935.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="98935" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.031</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'zwbbmXvRpoFhbgssWibN6lMJQVQB8jqN9g40_2F6VFP16IoFoOJN2xMvWQ20_2F9XxuqoWzPFhZZ8wKJY41plgO6WQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>