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>