现有两个dropdownlist(一左一右分布)..是为了表示地区的...左边的dropdwonlist的数据是从数据库中得来的..右边的dropdownlist的值是从左边的框里得来的..当点击添加按钮的时候...左边dropdownlist的值就添加到右边的dropdownlist中去...问题:左边的dropdownlist值不能和右边dropdownlist里的值重复..也就是说右边的dropdownlist的值是唯一的..不能有相同的....请问各高手怎么解决...写一下具体代码...

解决方案 »

  1.   

    primary key限制重复
    transaction控制一边删除一边添加
    对否?
      

  2.   

        
    protected void Button1_Click(object sender, EventArgs e)
    {
        ListItem l = new ListItem(DropDownList1.SelectedItem.Text,DropDownList1.SelectedItem.Value);
        if (!DropDownList2.Items.Contains(l))
        {
             DropDownList2.Items.Add(l);
        }        
    }
      

  3.   

    添加的时候用右边的Items.Contains来判断一下就行了
      

  4.   

    ???    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LeftDropDownList.Items.Add("item01");
                LeftDropDownList.Items.Add("item02");
                LeftDropDownList.Items.Add("item03");
            }
        }
        protected void LeftDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListItem selectItem = LeftDropDownList.SelectedItem;
            selectItem.Selected = false;        RightDropDownList.Items.Add(selectItem);
            LeftDropDownList.Items.Remove(selectItem);    }