当用户从下拉列表中选择一个值并单击按钮时,该值将添加到第二个列表(也显示在屏幕上)。
问题是当用户单击按钮时,所选值被添加到第二个列表中,但是下拉列表被复制并添加到原始下拉列表中。
所以我们在原始下拉列表中有 1、2、3,用户选择“1”并按下按钮。'1' 被添加到第二个列表并显示在屏幕上,但是当用户单击下拉列表时,它现在包含 2、3、1、2、3
我用断点检查了我的代码,我认为它与.dataSource有关。
protected void UpdatePage()
{
int Id = System.Convert.ToInt32(Id.Value);
List<Contractor> allContractors = new List<Contractor>();
ClarkeDBDataContext db = new ClarkeDBDataContext();
allSubContractors = (from BoqContractors in db.BOQ_Contractors
where BoqContractors.Bill_Of_Quantity_id == tempBoqId
select BoqContractors.Contractor).ToList();
repeaterShowContractorName.DataSource = allContractors;
repeaterShowContractorName.DataBind();
IEnumerable<Sub> availableContractors =
(from sc in db.Contractors
select sc).ToList().Except(allContractors);
//i've tried to set it to null to test it, but to no avail
DropDownListContractors.DataSource = null;
DropDownListContractors.DataSource = availableContractors;
DropDownListContractors.DataBind();
}