如果“全部选择”,如何禁用其他复选框列表?列表项目被选中了吗? [英] How do I disable other checkboxlist if "select all" listitem is selected?

查看:51
本文介绍了如果“全部选择”,如何禁用其他复选框列表?列表项目被选中了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表,其中复选框列表项使用存储过程填充。但是我在复选框列表中添加了全选列表项。



当选中全选时,如何禁用所有其他复选框列表项目?



ASPX

 <   asp:CheckBoxList  < span class =code-attribute>   ID   =  CheckBoxList1    runat   =   server    

高度 = 80px 宽度 = 500px AppendDataBoundItems = True ViewStateMode = 已启用 >
< asp:ListItem 已选择 = True 文字 < span class =code-keyword> = 全选 = 全选 > < / asp:ListItem >
< / asp:CheckBoxList >





ASPX.CS

  protected   void  Page_Load( object  sender,EventArgs e)
{


using (SqlConnection conn = new SqlConnection(dbConn))
{
尝试 // 调用存储过程
{

SqlCommand cmd = new SqlCommand(spddl,conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (!IsPostBack)
{
CheckBoxList1.DataSource = ds.Tables [ 0 ];
CheckBoxList1.DataTextField = ds.Tables [ 0 ]。列[ ID]的ToString();
CheckBoxList1.DataBind();



}
如果(IsPostBack)
{
Bind( );
}

}

catch (例外i)
{
bool exception = true ;
if (例外== true
{
// txtMessage.Text + = e.Message;
}
}
}
}

解决方案

 <   html  >  
< head >
< script src = http://code.jquery.com/jquery-1.11.3.min.js > < / script >
< script src = http://code.jquery.com/jquery-migrate-1.2.1.min.js > < / script > ;
< script >

(函数(){

( 输入[类型= '复选框'])的变化(函数( ){
调试器;
if((


Hi, I have a checkbox list which the checkboxlist items are populated using a stored procedure. However I added a "Select All" list item to the checkbox list.

How can I disable all other checkbox list items when "Select All" is checked?

ASPX

<asp:CheckBoxList ID="CheckBoxList1" runat="server" 

Height="80px" Width="500px" AppendDataBoundItems="True" ViewStateMode="Enabled">
<asp:ListItem Selected="True" Text="Select All" Value="Select All"></asp:ListItem>
</asp:CheckBoxList>



ASPX.CS

protected void Page_Load(object sender, EventArgs e)
{


    using (SqlConnection conn = new SqlConnection(dbConn))
    {
        try //Call stored procedure
        {

            SqlCommand cmd = new SqlCommand(spddl, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (!IsPostBack)
            {
                CheckBoxList1.DataSource = ds.Tables[0];
                CheckBoxList1.DataTextField = ds.Tables[0].Columns["ID"].ToString();
                CheckBoxList1.DataBind();



            }
            if (IsPostBack)
            {
                Bind();
            }

        }

        catch (Exception i)
        {
            bool exception = true;
            if (exception == true)
            {
                //txtMessage.Text += e.Message;
            }
        }
    }
}

解决方案

<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>


(function(){


("input[type='checkbox']").change(function(){ debugger; if((


这篇关于如果“全部选择”,如何禁用其他复选框列表?列表项目被选中了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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