Use JavaScript code to implement the invert selection function of various data controls.

Source: Internet
Author: User

It turned out to be very simple and similar to implementing this in C # language. It only calls two languages, and writing code in this way is also good for the system performance. : The function implemented by the invert selection.

Below we will write the two parts of the Code that implement the inverse selection. The control uses the GridView control.Copy codeThe Code is as follows: <asp: TemplateField HeaderText = "<input type = 'checkbox' id = 'cball' name = 'cball' onclick = 'selall (this. checked); '/> invert selection ">
<ItemTemplate>
<Input type = "checkbox" id = "cbName" name = "cbName" value = '<% # DataBinder. Eval (Container. DataItem, "ProductID") %>'/>
</ItemTemplate>
</Asp: TemplateField>

Then write JavaScript code to implement this function:Copy codeThe Code is as follows: <script type = "text/javascript">
Function selAll (boolValue)
{
Var obj = document. getElementsByName ("cbName ");
Var cbNameLen = obj. length;
If (cbNameLen> 1)
{
For (var I = 0; I <cbNameLen; I ++)
{
If (obj [I]. checked)
{
Obj [I]. checked = false;
}
Else
{
Obj [I]. checked = true;
}
}
}
Else
{
Obj. checked = boolValue;
}
}
Function clickBtnCheck ()
{
Var obj = document. getElementsByName ("cbName ");
Var cbNameLen = obj. length;
Var Flag = false;
If (cbNameLen> 0)
{
For (var I = 0; I <cbNameLen; I ++)
{
If (obj [I]. checked)
{
Flag = true;
Break;
}
}
If (Flag)
{
Return true;
}
Else
{
Alert ("select the record to be operated first! ");
Return false;
}
}
Else
{
Alert ("no record now, operation not allowed! ");
Return false;
}
}
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.