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

发布于 2024-12-03 15:35:10 字数 209 浏览 5 评论 0原文

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

I have nested repeater. And in child repeater there is a dropdownlist for each record.This dropdown contains static items that is 1,2,3 and now i want to check the user cannot selected a value twice from a group.Actually what is it..When i click on parent repeater it will show child repeater which contains records matched to the ID of parent record clicked. Now in child repeater there is dropdownlist filled by static values (1,2,3). And the child repeater can show max three records only. now i want a user cannot select a value twice from this group. how it will possible? Please help me. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2024-12-10 15:35:10

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

    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);
             }
         }
   }

You need to check that validation at the time of save data like below :

    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);
             }
         }
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文