如何从下拉菜单中删除特定项目 [英] How to delete a particular item from a drop down

查看:99
本文介绍了如何从下拉菜单中删除特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有多个下拉菜单,它们都显示相同的值.当我从一个下拉列表中选择一个特定项目时,我希望从下一个下拉列表中排除该选定项目.
我该怎么办?

感谢您的问候,
Amit

Hello all,

I have multiple drop downs, that all show the same values. When I select a particular item from one drop down, I want that selected item to be excluded from the next drop down.
How can I do that?

Thanks with Regards,
Amit

推荐答案

Sandeep Mewara是正确的.有两个下拉列表

我已经使用First方法完成了它.代码在aspx页面上是这样的

Sandeep Mewara is right.There are two Drop down list

I have done it using First method. the code is like this at aspx page

<asp:dropdownlist id="ddl1" runat="server" autopostback="True" onselectedindexchanged="ddl1_SelectedIndexChanged" xmlns:asp="#unknown">
   <asp:listitem>A</asp:listitem>
   <asp:listitem>B</asp:listitem>
   <asp:listitem>C</asp:listitem>
   <asp:listitem>D</asp:listitem>
   <asp:listitem>E</asp:listitem>
</asp:dropdownlist>
                
<td>
   <asp:dropdownlist id="ddl2" runat="server" xmlns:asp="#unknown">
      <asp:listitem>A</asp:listitem>
      <asp:listitem>B</asp:listitem>
      <asp:listitem>C</asp:listitem>
      <asp:listitem>D</asp:listitem>
      <asp:listitem>E</asp:listitem>
   </asp:dropdownlist>
</td>





在aspx.cs页面上





At aspx.cs page

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
    ddl2.Items.Remove(ddl1.SelectedItem);
}


您可以根据需要增强代码

[从WW:下一次要发布代码时,请使用pre标签.他们对代码进行格式化,就像我确定您已经在此处看到的那样,并使其更易于阅读.另外,只需花一点时间来修复粘贴时的多余空间.多花几秒钟的时间才能真正使答案更具可读性.]


You can enhance the code according to your desired need

[From WW: next time you want to post code, use the pre tags. They format the code like I''m sure you''ve seen on here and make it much easier to read. Also, just take a little time to fix the extra spaces from when you pasted it in. An extra few seconds can really make the answer much more readable.]


两个选项:
1.回发(部分或全部).从其他下拉菜单中过滤该值. (按如下所示过滤,删除该特定值)
2.使用Javascript处理客户端.上面有一个onchange处理程序.在onchange方法中,从其他下拉列表中删除选定的值.

尝试任何一种适合您的方法. (我会选择第二种方法!)

顺便说一句,如果dropdwons是依赖的,那么我不会从一开始就全部填充,而是在选择上一个时将它们填充为.
Two options:
1. have a postback (partial or full). Filter that value from other dropdowns. (filter as in, remove that specific value)
2. have it handled client side using Javascripts. have a onchange handler on them. In onchange method remove the selected value from other dropdowns.

Try any one that suits you. (I would go for second option!)

BTW, if the dropdwons are dependent then i would not fill all from start, instead i will fill them as an when the previous one is selected.


这篇关于如何从下拉菜单中删除特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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