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>