Get the App
SLTechnology News&Howtos  ›  Development  › 

ASP.NET server side how to control RadioButtonList,DropDownList,CheckBoxList value, assignment usage tutorial

Shulou Source: shulou.com Published: 2022-06-03 07:38:06 09月29日 Update

This article mainly introduces the "tutorial on the value and assignment of RadioButtonList,DropDownList,CheckBoxList on the ASP.NET server side". In the daily operation, I believe that many people have doubts about the value and assignment usage tutorial of how to control RadioButtonList,DropDownList,CheckBoxList on the ASP.NET server side. The editor consulted all kinds of materials and sorted out a simple and useful operation method, hoping to answer "how to control RadioButtonList,DropDownList on the ASP.NET server side." CheckBoxList value, assignment usage tutorial "doubts help!" Next, please follow the editor to study!

All three controls have an Items collection, and you can use the RepeatLayout and RepeatDirection properties to control the rendering of the list. If the value of RepeatLayout is Table, the list is rendered in the table. If set to Flow, the list will be rendered without any table structure. By default, the value of RepeatDirection is Vertical. Setting this property to Horizontal will render the list horizontally.

RadioButtonList: the control provides a single selection list (data source radio) of an option that has been selected. Like other list controls, RadioButtonList has an Items collection whose members correspond to each item in the list.

DropDownList: drop-down list selection. For some forms of input, the user must select an option from the list of applicable options (drop-down only selection).

CheckBoxList: a multi-select list that presents the data source to the user horizontally or vertically, and the user can select multiple item.

Since these three controls are server-side controls and need to be parsed on the client side, here are three server-side and client-side examples of these controls.

Server side

The copy code is as follows:

Choose one by one

Single selection two

Single selection of three

Choose one more.

Choose more than two.

Choose more than three

Drop down and choose one.

Drop-down option two

Drop-down option three

After being parsed by the browser

The copy code is as follows:

Choose one by one

Single selection two

Single selection of three

Choose one more.

Choose more than two.

Choose more than three

Drop down and choose one.

Drop-down option two

Drop-down option three

The operation for these three controls is nothing more than taking values and assigning values, which are done through Jquery and .cs.

Jquery operates on three kinds of controls

1 、 RadioButtonList

1) take a value

The copy code is as follows:

$("# RadioButtonList1") .change (function () {

/ / pops up the vale value of the selected item

Alert ($("input [name = 'RadioButtonList1']: checked") .val ())

/ / pops up the text value of the selected item

Alert ($("input [name = 'RadioButtonList1']: checked+label") .text ())

});

2) assignment

The copy code is as follows:

/ / the second option is selected by default

Var rbts = document.getElementsByName ("RadioButtonList1")

For (var I = 0; I

< rbts.length; i++) { if (rbts[i].value == "1") rbts[i].checked = "true"; } 2、DropDownList 1)取值 复制代码 代码如下: $("#DropDownList1").change(function () { //弹出选中项的Val值 alert($("#DropDownList1").val()); //弹出选中项的text值 alert($("#DropDownList1 option:selected").text()); }); 2)赋值 复制代码 代码如下: //默认选中第二项 var ddls = $("#DropDownList1 option"); for (var i = 0; i < ddl.length; i++) { if (ddl[i].value == "1") { ddl[i].selected = "true"; } } 3、CheckBoxList 1)取值 复制代码 代码如下: $("#CheckBoxList1 >

Input ") .click (function () {

Var arrval = []

Var val = ""

$("# CheckBoxList1: checkbox:checked") .each (function () {

/ / put the value of the selected item into the array arrval

Arrval.push ($(this) .val ()

})

/ / concatenate the vals in the array with','

Val = arrval.join (',')

/ / pops up all selected items to connect

Alert (val)

Var arrtext = []

Var text = ""

$("# CheckBoxList1: checkbox:checked") .each (function () {

/ / put the text value of the selected item into the arrtext array

Arrtext.push ($(this). Next (). Html ())

/ / use the data in the array to connect

Text = arrtext.join (",")

})

/ / pops up the text value of the selected item

Alert (text)

});

2) assignment

The copy code is as follows:

Var cbks = $("# CheckBoxList1 input [type = 'checkbox']")

For (var I = 0; I < cbks.length; iTunes +) {

If (CBKS [I] .value = = "1" | | CBKS [I] .value = = "2") {

Cbks [I]. True = "cbks"

}

}

At this point, on the "ASP.NET server-side how to control RadioButtonList,DropDownList,CheckBoxList values, assignment usage tutorial" is over, I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Code controls selections servers services drop-down tutorials three arrays learning data users clients clients properties forms situations data sources methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Xiaomi NVidia Shulou Tech Info