<table style="margin: 0 auto; width: 800px">
            <tr>
                <td>
                    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                    </asp:CheckBoxList></td>
                <td>
                    <asp:CheckBoxList ID="CheckBoxList2" runat="server">
                    </asp:CheckBoxList></td>
            </tr>
        </table>    public void BindCheckBoxList1()
    {
        for (int i = 0; i < 10; i++)
        {
            CheckBoxList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }
    public void BindCheckBoxList2()
    {
        for (int i = 0; i < 10; i++)
        {
            CheckBoxList2.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }
我想实现的效果就是第一排的选中了,第二排就变灰,取消选中,第二排就正常,这里指的都是某一行
比如选中其中一个3,那么另外一个3的复选框变灰,取笑选中的话就又恢复正常
 

解决方案 »

  1.   

    给checkbox编号!!第一排为1,2,3,4你去编历你如何得知是哪一行??
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
            function change(obj,id) {
                if (obj.checked) {
                    document.getElementById(id).disabled = 'disabled';
                }
                else {
                    document.getElementById(id).disabled = false;
                }
                
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">    
        <table>
        
        <asp:Repeater ID="rp" runat="server" onitemdatabound="rp_ItemDataBound">
        <AlternatingItemTemplate>
        <tr>
        <td>
        <asp:CheckBox ID="ckbOne" runat="server" />
        </td>
        <td>
        <asp:CheckBox ID="ckbTwo" runat="server" />
        </td>
        </tr>
        </AlternatingItemTemplate>
        <ItemTemplate>
        <tr>
        <td>
        <asp:CheckBox ID="ckbOne" runat="server" />
        </td>
        <td>
        <asp:CheckBox ID="ckbTwo" runat="server" />
        </td>
        </tr>
        </ItemTemplate>
        </asp:Repeater>    
        </table>
        </form>
    </body>
    </html>
    private DataTable GetDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ID", typeof(Int32)));        
            DataRow dr;
            for (int i = 0; i < 5; i++)
            {
                dr = dt.NewRow();
                dr[0] = i;
                dt.Rows.Add(dr);
            }
            return dt;
        }    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rp.DataSource = GetDataTable();
                rp.DataBind();
            }
        }
        protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                CheckBox ckbOne = e.Item.FindControl("ckbOne") as CheckBox;
                CheckBox ckbTwo = e.Item.FindControl("ckbTwo") as CheckBox;
                if (ckbOne != null && ckbTwo != null)
                {
                    ckbOne.Attributes.Add("onclick", string.Format("change(this,'{0}')", ckbTwo.ClientID));
                    ckbTwo.Attributes.Add("onclick", string.Format("change(this,'{0}')", ckbOne.ClientID));
                }
            }
        }
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        <script type="text/javascript" >
            function check(cb) {
                var cbl1 = "<%= CheckBoxList1.ClientID %>";
                var cbl2 = "<%= CheckBoxList2.ClientID %>";
                var cb2;
                if (cb.id.indexOf(cbl1) > -1) {
                    cb2 = document.getElementById(cb.id.replace(cbl1, cbl2));
                }
                else {
                    cb2 = document.getElementById(cb.id.replace(cbl2, cbl1));
                }
                cb2.checked = !cb.checked;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <table style="margin: 0 auto; width: 800px">
                <tr>
                    <td>
                        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                        </asp:CheckBoxList></td>
                    <td>
                        <asp:CheckBoxList ID="CheckBoxList2" runat="server">
                        </asp:CheckBoxList></td>
                </tr>
            </table>
        </form>
    </body>
    </html>        protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindCheckBoxList1();
                    BindCheckBoxList2();
                }
            }        public void BindCheckBoxList1()
            {
                for (int i = 0; i < 10; i++)
                {
                    CheckBoxList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
                    CheckBoxList1.Items[i].Attributes.Add("onclick", "check(this)");
                }
            }
            public void BindCheckBoxList2()
            {
                for (int i = 0; i < 10; i++)
                {
                    CheckBoxList2.Items.Add(new ListItem(i.ToString(), i.ToString()));
                    CheckBoxList2.Items[i].Attributes.Add("onclick", "check(this)");            }
            }