Using JavaScript code to implement the reverse function of various data controls don't just drag the control's rookie _ Practical tips

Source: Internet
Author: User
The original is also very simple and use the C # language to achieve this kind of it, but to the two languages, and so write code on the performance of the system is also better. As shown in the figure: the features implemented for the inverse of the selection.

The following two parts of the implementation of the optional code to write Oh. Control is using the GridView control
Copy Code code as follows:

<asp:templatefield headertext= "<input type= ' checkbox ' id= ' cball ' name= ' cball ', ' onclick= '" Selall "(this.checked); ' /> Anti-election ">
<ItemTemplate>
<input type= "checkbox" id= "CBName" name= "cbname" Value= ' <%# DataBinder.Eval (Container.DataItem, "ProductID")% > '/>
</ItemTemplate>
</asp:TemplateField>

Then write the JavaScript code to implement this feature:
Copy Code code 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 you want to manipulate first!") ");
return false;
}
}
Else
{
Alert ("No record now, no operation!") ");
return false;
}
}
</script>

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.