启用或选中数据列表中的所有复选框 [英] Enable or check all the checkbox inside datalist

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

问题描述



我有datalist,其中有复选框列表.数据列表项之一是ALL.如果用户选中了ALL(复选框),那么我要选中所有剩余的复选框或禁用所有剩余的复选框.

我正在使用下面给出的代码,但是它不起作用.告诉我一些有效的方法.

Hi,

I am having datalist which is having list of checkboxes. One of the datalist item is ALL. If user check that ALL(checkbox), then I want to check all remaining checkboxes or disable all the remaining checkboxes.

I am using the below given code, but it is not working. Tell me some efficient way to do this.

protected void chkFacilityChanged(object sender,   EventArgs e)
    { 
        foreach (DataListItem rptItem in rptFactility.Items)
        {
           CheckBox allchk = (CheckBox)rptItem.FindControl("chkFacility").ToString();
          string  facilityCode = rptItem.FindControl("lblFacilityCode").ToString();
           if ( facilityCode.Text.ToString() = "0"   && allchk.checked)
             {                 
                allchk1.Checked = true;
               //rptItem1.Enabled = false;
                }
               return;
            }
        }
}




OR

protected void chkFacilityChanged(object sender,   EventArgs e)
    {
        foreach (DataListItem rptItem in rptFactility.Items)
        {
           CheckBox allchk = (CheckBox)rptItem.FindControl("chkFacility").ToString();

          string  facilityCode = rptItem.FindControl("lblFacilityCode").ToString();
           if ( facilityCode.Text.ToString() = "0"   && allchk.checked)
             {
               foreach (DataListItem rptItem1 in rptFactility.Items)
        {
                CheckBox allchk1 = (CheckBox)rptItem.FindControl("chkFacility").ToString();

                allchk1.Checked1 = true;
               //rptItem1.Enabled = false;
                }
               return;
            }
        }
}

推荐答案

告诉我一些有效的方法.
使用JavaScript在客户端进行操作.

您可能需要遍历数据列表",然后选择全选"或全部禁用".
Tell me some efficient way to do this.
Do it client side, using JavaScript.

You would need to loop though the Datalist and Select All or Disable all the items one by one.


您好,

这是一个很好的示例,在Gridview中取消选中所有复选框 [ ^ ].只需用您的DataList控件ID替换GridView ID.
hello,

Here is a good example Check uncheck all checkboxes in Gridview[^]. Just replace the GridView id with your DataList control ID.


您好,
您可以通过jquery来做到.
容器引用一个jquery对象(您的datalist对象).

var checkboxes = container.find("input [type =" checkbox]");
那么您可以在客户端循环和操作它.
there
you can do it by jquery.
container refer to a jquery object(your datalist object).

var checkboxes = container.find("input[type=''checkbox'']");
then you can loop and operate it in client side.


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

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