datagrid|javascript| function JavaScript to implement the full selection of the DataGrid Client CheckBox column, and select
Author: unknown
Source: Network
/**//* Paging
Parameter description:
Prefix: prefix; chkall: all marquee; Chksingle: Radio Box ID
How to use:
if (E.item.itemtype = = Listitemtype.header)
{
(CheckBox) e.item.cells[1]. FindControl ("Chkall")). Attributes.Add ("onclick", "checkall (' + this.dg.ClientID.ToString () +" ', ' chkall ', ' chksingle '); ");
}
*/
function Checkall (prefix,chkall,chksingle)
{
var Indexchkall;
if (prefix.length!= 0)
{
Indexchkall = prefix + "__ctl2_" + chkall;
}
Else
{
Indexchkall = Chkall;
}
var objchkall = Do***ent.getelementbyid (Indexchkall);
var tempobj;
for (Var i=0;i<do***ent.forms[0].elements.length;i++)
{
Tempobj = do***ent.forms[0].elements;
if (Tempobj.type = "checkbox" && tempobj.id!= indexchkall && tempObj.id.indexOf (chksingle)!=-1)
{
tempobj.checked = objchkall.checked;
}
}
}
/**//* Paging
Parameter description:
Prefix: prefix; chkall: all marquee; Chksingle: Radio Box ID
How to use:
if (E.item.itemtype = = ListItemType.AlternatingItem | | e.item.itemtype = = listitemtype.item)
{
(CheckBox) e.item.cells[1]. FindControl ("Chksingle")). Attributes.Add ("onclick", "checksingle (' + this.dg.ClientID.ToString () +" ', ' chkall ', ' chksingle '); ");
}
*/
function Checksingle (prefix,chkall,chksingle)
{
var Indexchkall;
if (prefix.length!= 0)
{
Indexchkall = prefix + "__ctl2_" + chkall;
}
Else
{
Indexchkall = Chkall;
}
var objchkall = Do***ent.getelementbyid (Indexchkall);
var tempobj;
var allcount = 0;
var checkcount = 0;
for (Var i=0;i<do***ent.forms[0].elements.length;i++)
{
Tempobj = do***ent.forms[0].elements;
if (Tempobj.type = "checkbox" && tempobj.id!= indexchkall && tempObj.id.indexOf (chksingle)!=-1)
{
if (tempobj.checked)
{
checkcount++;
}
Else
{
objchkall.checked = false;
Break
}
allcount++;
}
}
if (Checkcount!= allcount)
{
objchkall.checked = false;
}
Else
{
if (allcount!= 0)
{
Objchkall.checked = true;
}
}
}
/**//*
Parameter description:
Prefix: prefix; chkall: all marquee; Chksingle: Radio Box ID
Type:1 "Select All", 2 "anti-election", 3 "Cancel"
How to use:
THIS.BTNSELECTALL.ATTRIBUTES.ADD ("OnClick", "Checktype (") + this.dg.ClientID.ToString () + "', ' chkall ', ' Chksingle ', 1 );");
THIS.BTNUNSELECTALL.ATTRIBUTES.ADD ("OnClick", "Checktype") (' + this.dg.ClientID.ToString () + "', ' chkall ', ' Chksingle ') , 2); ");
THIS.BTNCANCELSELECT.ATTRIBUTES.ADD ("OnClick", "Checktype" "+ this.dg.ClientID.ToString () +" ", ' Chkall ', ' Chksingle ', 3; ");
*/
function Checktype (prefix,chkall,chksingle,type)
{
var Indexchkall;
if (prefix.length!= 0)
{
Indexchkall = prefix + "__ctl2_" + chkall;
}
Else
{
Indexchkall = Chkall;
}
var objchkall = Do***ent.getelementbyid (Indexchkall);
var tempobj;
var allcount = 0;
var checkcount = 0;
for (Var i=0;i<do***ent.forms[0].elements.length;i++)
{
Tempobj = do***ent.forms[0].elements;
if (Tempobj.type = "checkbox" && tempobj.id!= indexchkall && tempObj.id.indexOf (chksingle)!=-1)
{
Switch (type)
{
Case 1:
Tempobj.checked = true;
Break
Case 2:
tempobj.checked =!tempobj.checked;
Break
Case 3:
tempobj.checked = false;
Break
}
if (tempobj.checked)
{
checkcount++;
}
allcount++;
}
}
if (Checkcount!= allcount)
{
objchkall.checked = false;
}
Else
{
if (allcount!= 0)
{
Objchkall.checked = true;
}
}
Window.event.returnValue = false;
return false;
}
/**//*
Parameter description:
Prefix: prefix; chkall: all marquee; Chksingle: Radio Box ID
How to use:
THIS.BTNDELETE.ATTRIBUTES.ADD ("OnClick", "Submitcheckbox") (' + this.dg.ClientID.ToString () + "', ' chkall ', ' Chksingle ') );");
*/
function Submitcheckbox (prefix,chkall,chksingle,msg)
{
var Indexchkall;
if (prefix.length!= 0)
{
Indexchkall = prefix + "__ctl2_" + chkall;
}
Else
{
Indexchkall = Chkall;
}
var objchkall = Do***ent.getelementbyid (Indexchkall);
var tempobj;
var allcount = 0;
var checkcount = 0;
for (Var i=0;i<do***ent.forms[0].elements.length;i++)
{
Tempobj = do***ent.forms[0].elements;
if (Tempobj.type = "checkbox" && tempobj.id!= indexchkall && tempObj.id.indexOf (chksingle)!=-1)
{
if (tempobj.checked)
{
checkcount++;
}
allcount++;
}
}
if (allcount = 0)//No data
{
Window.alert ("not currently" + MSG + "available for deletion");
Window.event.returnValue = false;
return false;
}
Else
{
if (checkcount = 0)
{
Window.alert ("+ msg +" "Not selected for deletion);
Window.event.returnValue = false;
return false;
}
Else
{
If Window.confirm ("OK to delete the currently selected" "+ checkcount.tostring () +" "Item?) ") = = False)
If Window.confirm ("Are you sure you want to delete the currently selected + MSG +"?) ") = = False)
{
Window.event.returnValue = false;
return false;
}
}
}
}