下拉列表的**选定值不能重复**

时间:2011-09-08 06:35:17

标签: asp.net drop-down-menu nested-repeater

我有嵌套转发器。在儿童中继器中,每个记录都有一个下拉列表。这个下拉列表包含静态项目1,2,3现在我想检查用户无法从组中选择两次值。实际上它是什么...当我点击在父转发器上,它将显示子转发器,其中包含与单击的父记录的ID匹配的记录。现在在子转发器中,有一个由静态值填充的下拉列表(1,2,3)。儿童中继器只能显示最多三个记录。现在我希望用户无法从该组中选择两次值。怎么可能?请帮我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您需要在保存数据时检查验证,如下所示:

    String[] arrSelectedValues = null;
    foreach (RepeaterItem itemParent in rptTest.Items)
    {
         Repeater rptChild = (Repeater)itemParent.FindControl("rptChild");
         if (rptChild != null)
         {
             foreach (RepeaterItem item in rptChild.Items)
             {
                 DropDownList ddlTest = (DropDownList)item.FindControl("ddlTest");
                 if (arrSelectedValues.Contains(ddlTest.SelectedValue)
                 {
                   // Write code to fire validation here
                 }
                 else
                   arrSelectedValues.Add(ddlTest.SelectedValue);
             }
         }
   }
相关问题