全选复选框 [英] select all in check box

查看:93
本文介绍了全选复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

如何使用全选按钮选择所有复选框.

Hi ...

how can select all check box using select All button.

推荐答案

尝试以下操作:
对于C#:
Try this:
For C#:
private void SelectAllCheckBoxControls(Control parent,bool checkedVal)
            {
            try
                {
                string strLeave=string.Empty;
                foreach (Control child in parent.Controls)
                    {
                    if (child.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
                        {
                        CheckBox chk = (CheckBox)child;
                        chk.Checked=checkedVal;
                        }
                    }
                }
             catch(Exception exp)
                {
                throw new Exception("SelectAllCheckBoxControls  " + exp.Message);
                }
            }


对于JavaScript:


For JavaScript:

var checkboxes = document.getElementById( 'boxes' ).getElementsByTagName( 'input' );
for ( var i = 0; i < checkboxes.length; i++ )
{
    if ( checkboxes[i].type == 'checkbox' )
    {
        checkboxes[i].chcked = true;
    }
}


可用于Windows以及Asp.net应用程序.

使用CheckboxList控件.
并使用以下代码
foreach(chklst.Items中的ListItem lst){
lst.Selected = true;
}

在这里chklst只是CheckboxList控件

希望这段代码对您有所帮助.

最好的问候,
阿尼尔·阿夫哈德(印度)
useful for Windows as well as Asp.net Application.

Use CheckboxList control.
and use following code
foreach(ListItem lst in chklst.Items) {
lst.Selected = true;
}

here chklst is nothing but CheckboxList control

Hope, this code will be helpful for you.

Best Regards,
Anil Avhad(India)


这篇关于全选复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆