文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>javascript配合DataGrid操作常用函数

javascript配合DataGrid操作常用函数

时间:2007-03-21  来源:yakecoco

javascript实现datagrid客户端checkbox列的全选,反选。 参数说明: 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=document.getElementById(indexChkAll); var tempObj; for(var i=0;i<document.forms[0].elements.length;i++) {   tempObj=document.forms[0].elements[i];   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 = document.getElementById(indexChkAll);
    var tempObj;
    var allCount    = 0;
    var checkCount    = 0;
    for(var i=0;i<document.forms[0].elements.length;i++)
    {   
        tempObj = document.forms[0].elements[i];
        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 = document.getElementById(indexChkAll);
    var tempObj;
    var allCount    = 0;
    var checkCount    = 0;
    for(var i=0;i<document.forms[0].elements.length;i++)
    {   
        tempObj = document.forms[0].elements[i];
        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 = document.getElementById(indexChkAll);
   
    var tempObj;
    var allCount    = 0;
    var checkCount    = 0;
    for(var i=0;i<document.forms[0].elements.length;i++)
    {   
        tempObj = document.forms[0].elements[i];
        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;
            }
        }
    }
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载