作者:未知
来源:网络
/**//* 分页
参数说明:
prefix:前缀;chkAll:全选框;chkSingle:单选框ID
使用方法:
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;
}
}
}
/**//* 分页
参数说明:
prefix:前缀;chkAll:全选框;chkSingle:单选框ID
使用方法:
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;
}
}
}
/**//*
参数说明:
prefix:前缀;chkAll:全选框;chkSingle:单选框ID
type:1【全选】,2【反选】,3【取消】
使用方法:
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;
}
/**//*
参数说明:
prefix:前缀;chkAll:全选框;chkSingle:单选框ID
使用方法:
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) //没有数据
{
window.alert("当前没有" + msg + "可供删除");
window.event.returnValue = false;
return false;
}
else
{
if(checkCount == 0)
{
window.alert("没有选中要删除的" + msg + "");
window.event.returnValue = false;
return false;
}
else
{
//if(window.confirm("确定要删除当前选中的【" + checkCount.toString() + "】项吗?") == false)
if(window.confirm("确定要删除当前选中的" + msg + "吗?") == false)
{
window.event.returnValue = false;
return false;
}
}
}
}