JavaScript used in conjunction with DataGrid operations Common functions

Source: Internet
Author: User
Tags functions return tostring window
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;
}
}
}
}




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.