这段程序可以从listbox1选择数据添加到listbox2去,但想加多个功能,如果往listbox2中加已经存在的项,会提示部能添加,那个判断条件怎样写?<%@ Page Language="C#"%><script runat="server">void lstProducts_SelectedIndexChanged(Object sender, EventArgs e)
{
if (lstCart.SelectedItem==null || lstProducts.SelectedItem.Text != lstCart.Items)//?(判断:如果重复就不能加进去,这句部知道怎样写,部知道怎样来获取来1stCart中某个项的值,selectedItem不行。求助~)
{
lstCart.SelectedIndex = -1;
lstCart.Items.Add(lstProducts.SelectedItem);
}
else
{
message.Text = "hihi";
}
}
void btnRemove_Click(Object sender, EventArgs e)
{
lstCart.Items.Remove( lstCart.SelectedItem );
}
void btnRemoveAll_Click(Object sender, EventArgs e)
{
lstCart.Items.Clear();
}</Script><html>
<head><title>ListItemCollection.aspx</title></head>
<body><form id="Form1" Runat="Server"><h2>Products:</h2>
<asp:ListBox
id="lstProducts"
Width="200"
AutoPostBack="True"
OnSelectedIndexChanged="lstProducts_SelectedIndexChanged"
SelectionMode="Multiple"
Runat="Server">
<asp:ListItem Text="Hair Dryer"/>
<asp:ListItem Text="Shaving Cream"/>
<asp:ListItem Text="Electric Comb"/>
<asp:ListItem Text="Nail Polish"/>
<asp:ListItem Text="French Toast"/>
</asp:ListBox><p><h2>Shopping Cart:</h2>
<asp:ListBox
ID="lstCart"
Width="200"
SelectionMode="Multiple"
Runat="Server"/>
<br>
<asp:Button
id="btnRemove"
Text="Remove Item"
OnClick="btnRemove_Click"
Runat="Server"/><asp:Button
id="btnRemoveAll"
Text="Remove All"
OnClick="btnRemoveAll_Click"
Runat="Server"/><asp:Label ID="message" Runat="Server" />
</form>
</body>
</html>
{
if (lstCart.SelectedItem==null || lstProducts.SelectedItem.Text != lstCart.Items)//?(判断:如果重复就不能加进去,这句部知道怎样写,部知道怎样来获取来1stCart中某个项的值,selectedItem不行。求助~)
{
lstCart.SelectedIndex = -1;
lstCart.Items.Add(lstProducts.SelectedItem);
}
else
{
message.Text = "hihi";
}
}
void btnRemove_Click(Object sender, EventArgs e)
{
lstCart.Items.Remove( lstCart.SelectedItem );
}
void btnRemoveAll_Click(Object sender, EventArgs e)
{
lstCart.Items.Clear();
}</Script><html>
<head><title>ListItemCollection.aspx</title></head>
<body><form id="Form1" Runat="Server"><h2>Products:</h2>
<asp:ListBox
id="lstProducts"
Width="200"
AutoPostBack="True"
OnSelectedIndexChanged="lstProducts_SelectedIndexChanged"
SelectionMode="Multiple"
Runat="Server">
<asp:ListItem Text="Hair Dryer"/>
<asp:ListItem Text="Shaving Cream"/>
<asp:ListItem Text="Electric Comb"/>
<asp:ListItem Text="Nail Polish"/>
<asp:ListItem Text="French Toast"/>
</asp:ListBox><p><h2>Shopping Cart:</h2>
<asp:ListBox
ID="lstCart"
Width="200"
SelectionMode="Multiple"
Runat="Server"/>
<br>
<asp:Button
id="btnRemove"
Text="Remove Item"
OnClick="btnRemove_Click"
Runat="Server"/><asp:Button
id="btnRemoveAll"
Text="Remove All"
OnClick="btnRemoveAll_Click"
Runat="Server"/><asp:Label ID="message" Runat="Server" />
</form>
</body>
</html>
解决方案 »
- 急~CuteEditor 在asp.net C#里 可不可以不要清楚word格式啊
- asp.net调用JS文件
- 这是我写的查询文章, 但是查询单号,不行。看看错再哪了??
- 问两个常用知识点... 谢谢 大家解答
- 如何模拟得到DrawString所得到的尺寸大小?
- 奇怪的事,哪位帮我试一下,这个脚本怎么会被执行了两次
- 在.CS中对当前页面中的属性的修改怎么写,例如修改页面的bgColor,title,注意是页面不是控件!!
- 怎样判断页面被请求时有无参数?谢谢!
- 现在有一个DataTable,Table里有一条记录,关于如何修改它的值如何办?
- 操作DataTime问题?
- avtivereport生成表的问题,送100分,请指教
- 求统计方法
for(i=0;i<this.lstCart.Items.Count;i++)
{
if(this.lstCart.Items[i].Value==lstProducts.SelectedItem.Value)
{
j=1;
break;
}
}
if(j==0)
this.lstCart.Items.Add(new ListItem(lstProducts.SelectedItem.Text,lstProducts.SelectedItem.Value));