提出两个复选框列表互斥 [英] Make two checkbox lists mutually exclusive

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

问题描述

好日子的朋友,

我知道怎么才能让两个复选框或复选框互斥的一个复选框列表中。
但是我的问题是从一点不同,希望得到堆栈溢出一些帮助,

I got to know how we can make two checkboxes or checkboxes inside a checkbox list mutually exclusive. However my question is little different from that, Hope to get some help from stack overflow,

好吧,我有两个复选框列表如下,并从数据表中我得到的复选框值,

Well I have two checkbox lists, as follows and from a dataset table I am getting the check box values,

CheckBoxlist1 - Checkbox_selectColumns

CheckBoxlist1 - Checkbox_selectColumns

 if (IsDataSetNotEmpty(ds))
 {
   CheckBox_selectColumns.Items.Clear();
   foreach (DataRow row in ds.Tables[0].Rows)
   {
     CheckBox_selectColumns.Items.Add(row[0].ToString());
   }

 }

CheckBoxlist2 - Checkbox_selectFields

CheckBoxlist2 - Checkbox_selectFields

if (IsDataSetNotEmpty(ds))
{
  Checkbox_selectFields.Items.Clear();
  foreach (DataRow row in ds.Tables[1].Rows)
  {
    CheckBox_selectColumns.Items.Add(row[0].ToString());
  }

}

我将在每一个名单得到以下复选框。

I will get following checkboxes in each lists.

Checkbox_selectColumns:雇员ID,名字,姓

Checkbox_selectColumns : Employee ID, First Name, Last Name

Checkbox_selectFields:经理ID,经理FName参数,经理LName的

Checkbox_selectFields : manager ID, Manager FName, Manager LName

有什么办法,我可以使这两个复选框互斥,即如果我选择第一个列表中的任何一个或多个复选框,我不应该选择第二个列表中,反之亦然。

Is there any way , I can make these two checkboxes mutually exclusive, That is if I select any one or more checkbox from first list, I should not select any checkboxes from second list and vice versa..

感谢您......

推荐答案

而不是通过在复选框中的项目循环,我建议使用的在的SelectedValue 属性控制,因为这一直持续到回传(的SelectedIndex 不)(<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue.aspx\"相对=nofollow> ListControl.SelectedValue物业):

Rather than loop through the items in the CheckBox, I'd suggest using the SelectedValue property of the control, as that persists through postbacks (SelectedIndex does not) (ListControl.SelectedValue Property):

protected void CheckBox_selectColumns_SelectedIndexChanged(object sender, EventArgs e)         
{             

    if (CheckBox_selectColumns.SelectedValue != "")
    {
        foreach (ListItem listItem in CheckBox_SelectAll.Items)
        {
            listItem.Selected = false;
        }
    }
}

protected void CheckBox_SelectAll_CheckChanged(object sender, EventArgs e)
{

    if (CheckBox_SelectAll.SelectedValue != "")
    {
        foreach (ListItem listItem in CheckBox_selectColumns.Items)
        {
            listItem.Selected = false;
        }
    }
}

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

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