The following code implements the features we often encounter: When handling Email in the web page, there will be all selected or canceled Checkbox, and add the selected content to a TextBox.
There are two ways to implement: We assume that the mailing list is implemented with DataList, add CheckBox1 to the ItemTemplate to bind the library.
Using server control: Implemented in Checkbox's CheckedChanged event.
Private void CBSelectAll_Checkedchanged (Object Sender, System.Eventargs E)
{
IF (cbselectall.checked)
{
Checkbox CurrentCheckbox = new checkbox ();
Foreach (DatalistItem ItemChecked in Datalist1.Items)
{
CurrentCheckBox = (CHECKBOX) (ItemChecked.FindControl ("CheckBox1"));
CurrentCheckbox.checked = true;
}
}
Else
{
Checkbox CurrentCheckbox = new checkbox ();
Foreach (DatalistItem ItemChecked in Datalist1.Items)
{
CurrentCheckBox = (CHECKBOX) (ItemChecked.FindControl ("CheckBox1"));
CurrentCheckBox.checked = false;
}
}
}
This method is disadvantage that the reaction is too slow and does not adapt to customer needs.
Another way is to use JavaScript:
Add in HTML
Function SelectAll ()
{
Var arrobj = document.all;
IF (document.form1.checkedall.checked)
{
For (var i = 0; i { IF (TypeOf Arrobj [I] .Type! = "undefined" && arrobj [i] .type == 'checkbox') { Arrobj [i] .checked = true; } } } Else { For (var i = 0; i { IF (TypeOf Arrobj [i] .Type! = "undefined" && arrobj [i] .type == 'checkbox') arrobj [i] .Checked = false; } } } script> Add οnclick = "selectall ()" in CHECKBOX, as follows: For selecting lists, how do we join the contents to a TextBox? The name of the CheckBoxList here is CBLNAME, TextBox is TextBox1. The implementation function is to add the selected CheckBoxList's fieldtext to TextBox and separated by a semicolon.