选中的下拉列表项目名称在其他下拉列表中不可见 [英] selected dropdownlist item name cannot visible in the other dropdown
问题描述
假设我有三个DropDownLists,每个都包含以下项目:A,B,C,D和E.these正在从表数据中恢复。如果我从DropDownList 2中选择了项目D,则DropDownList1和3将仅显示项目A,B,C和E,因为我的代码用于从其他DropDownLists中删除/禁用所选项目。我想添加选择选项对于所有下拉列表,如果我点击它不会去'选择'选项。任何的想法?请帮忙。
谢谢
检查下面的代码和平。它可能对你有帮助。
假设我们有3个dorpdown。
< asp:DropDownList ID = DropDownList1 runat = server < span class =code-attribute> 宽度 = 150px
AutoPostBack = True onselectedindexchanged < span class =code-keyword> = DropDownList1_SelectedIndexChanged >
< asp:ListItem > a < / asp:ListItem >
< asp:ListItem > b < / asp:ListItem >
< asp:ListItem > c < / asp:ListItem >
< asp:ListItem > 1 < / asp:ListItem >
< asp:ListItem > 2 < / asp:ListItem >
< asp:ListItem > 3 < / asp:ListItem >
< asp:ListItem > < < span class =code-leadattribute> / asp:ListItem >
< / asp:DropDownList >
< br / >
< asp:DropDownList ID = DropDownList2 runat = server 宽度 = 150px
AutoPostBack = True onselectedindexchanged = DropDownList2_SelectedIndexChanged >
< asp:ListItem > a < / asp:ListItem >
< asp:ListItem > b < / asp:ListItem >
< asp:ListItem < span class =code-keyword>> c< / asp:ListItem >
< asp:ListItem > 1 < / asp:ListItem >
< asp:ListItem > 2 < / asp:ListItem >
< asp:ListItem > 3 < / asp:ListItem >
< asp:ListItem > < ; / asp:ListItem >
< / asp:DropDownList >
< br / >
< asp:DropDownList ID = DropDownList3 runat = server 宽度 = 150px
< span class =code-attribute> AutoPostBack = True onselectedindexchanged = DropDownList3_SelectedIndexChanged >
< asp:ListItem > a < / asp:ListItem >
< asp:ListItem > b < / asp:ListItem >
< < span class =code-leadattribute> asp:ListItem > c < < span class =code-leadattribute> / asp:ListItem >
< asp:ListItem > 1 < / asp:ListItem >
< asp:ListItem > 2 < / asp:ListItem >
< asp:ListItem > 3 < / asp:ListItem >
< asp: ListItem > < / asp: ListItem >
< / asp:DropDownList >
以下是代码背后的代码。
protected void DropDownList1_SelectedIndexChanged( object sender,EventArgs e)
{
string item = DropDownList1.Text;
DropDownList2.Items.Remove(item);
DropDownList3.Items.Remove(item);
}
protected void DropDownList2_SelectedIndexChanged( object sender,EventArgs e)
{
string item = DropDownList2.Text;
DropDownList1.Items.Remove(item);
DropDownList3.Items.Remove(item);
}
protected void DropDownList3_SelectedIndexChanged( object sender,EventArgs e)
{
string item = DropDownList3.Text;
// 在这里,您可以绑定Dropdown,然后删除该项目。在您需要的任何地方执行此操作
DropDownList1.Items.Remove(item);
DropDownList2.Items.Remove(item);
}
如果你想在页面加载上做类似的事情,你也可以根据上面的代码来做。
Suppose I have three DropDownLists each with the items: A, B,C,D and E.these are retriving from table data. If I selected item D from the DropDownList 2, then DropDownList1 and 3 will show the items A, B, C and E only, since my code works to remove / disable the selected item from the other DropDownLists.and i want to add Select option for all dropdownlist, if i click on that it wont go 'select' option. Any idea? Please help.
Thank You
Check below peace of code. It might help you.
Let's say we have 3 dorpdown.
<asp:DropDownList ID="DropDownList1" runat="server" Width="150px" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>a</asp:ListItem> <asp:ListItem>b</asp:ListItem> <asp:ListItem>c</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem></asp:ListItem> </asp:DropDownList> <br /> <asp:DropDownList ID="DropDownList2" runat="server" Width="150px" AutoPostBack="True" onselectedindexchanged="DropDownList2_SelectedIndexChanged"> <asp:ListItem>a</asp:ListItem> <asp:ListItem>b</asp:ListItem> <asp:ListItem>c</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem></asp:ListItem> </asp:DropDownList> <br /> <asp:DropDownList ID="DropDownList3" runat="server" Width="150px" AutoPostBack="True" onselectedindexchanged="DropDownList3_SelectedIndexChanged"> <asp:ListItem>a</asp:ListItem> <asp:ListItem>b</asp:ListItem> <asp:ListItem>c</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem></asp:ListItem> </asp:DropDownList>
Below is the code behind code.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string item = DropDownList1.Text; DropDownList2.Items.Remove(item); DropDownList3.Items.Remove(item); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string item = DropDownList2.Text; DropDownList1.Items.Remove(item); DropDownList3.Items.Remove(item); } protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) { string item = DropDownList3.Text; //here you can bind the Dropdown and then remove the item. Do this wherever you require to do DropDownList1.Items.Remove(item); DropDownList2.Items.Remove(item); }
If you want to do something similar on Page Load you can do that also based on above code.
这篇关于选中的下拉列表项目名称在其他下拉列表中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!