从两个下拉列表中删除同一项目 [英] Removing same item from two dropdown list
问题描述
大家好,我要在我的注册表中添加两个下拉列表.第一个下拉列表绑定到数据库,第二个下拉列表也来自同一表.如果我从firstdropdownlist中选择一个项目,则从第二个dropdownlist中删除该项目.对我来说没关系,但是问题是我单击了firstdropdown列表的所有项目,而不是第二个dropdownlist变为空.请参阅我的代码
Hi to all, i am adding two dropdown list in my registration form. the first dropdownlist is bind to database, and second dropdownlist also from same table. if i select a item from firstdropdownlist it remove the item from second dropdownlist. That is Ok for me, but the problem is that i click all item of firstdropdown list than the second dropdownlist become empty.. See my code
<asp:DropDownList ID="DrpPrefLangauge1"
AppendDataBoundItems ="true"
OnSelectedIndexChanged="DrpPrefLangauge1_SelectedIndexChanged"
runat="server"
AutoPostBack="True">
<asp:ListItem Text="----Select----"
Value="0">
</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DrpPrefLangauge2"
AppendDataBoundItems="true"
runat="server">
<asp:ListItem Text="----Select----"
Value="0">
</asp:ListItem>
</asp:DropDownList>
在后面的代码中:
At code behind:
protected void setLangauge()
{
nsBusinessLogicLayer.LanguageInfo objLanguageInfo = new nsBusinessLogicLayer.LanguageInfo();
nsAbstractLayer.LanguageInfoAbstract objLanguageInfoAbstract = new nsAbstractLayer.LanguageInfoAbstract();
//objLanguageInfoAbstract.Languageid = Convert.ToInt64(DrpPrefLangauge1.SelectedValue);
DataTable dt = objLanguageInfo.Search(objLanguageInfoAbstract);
DrpPrefLangauge1.DataSource = dt;
DrpPrefLangauge1.DataTextField = "LanguageName";
DrpPrefLangauge1.DataValueField = "Languageid";
DrpPrefLangauge1.DataBind();
DrpPrefLangauge2.DataSource = dt;
DrpPrefLangauge2.DataTextField = "LanguageName";
DrpPrefLangauge2.DataValueField = "Languageid";
DrpPrefLangauge2.DataBind();
}
在选定的索引上:
ON selected index:
protected void DrpPrefLangauge1_SelectedIndexChanged(object sender, EventArgs e)
{
ListItem value = DrpPrefLangauge1.SelectedItem;
//int index=DrpPrefLangauge2.Items.IndexOf(value);
DrpPrefLangauge2.Items.Remove(value);
}
我想如果我从firstdownlist中选择说印地文langauge,它将在第二个dropdownlist中删除.这是可行的,但是如果我从我的第一个downlist中选择所有项目,则第二个dropdownlist变为空..这就是问题的解决方法..
I want if i select say hindi langauge from firstdownlist , it will remove in second dropdownlist.. this is working but if i select all item from my first downlist the second dropdownlist become empty..that is the problem how it solve it..
推荐答案
如果您打算保留除DrpPrefLanguage1中所选项目之外的所有项目,则必须在删除该项目之前重新绑定DrpPrefLanguage2.
希望对您有所帮助.
-------------------------------------------------- -------------
签名:瓜达卢斯伊比利亚州
If your intention is to keep all items with the exception of the selected item in DrpPrefLanguage1, you must rebind DrpPrefLanguage2 before removing the item.
I hope this helps.
---------------------------------------------------------------
Signature: Imobiliárias em Guarulhos
您不能同时拥有这两种方式.如果您希望在选择某个项目时将其删除,那么在选择所有项目时,它们都将被删除.
You can''t have it both ways. If you want an item removed when selected then when selecting all items they will all be removed.
这篇关于从两个下拉列表中删除同一项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!