兩個LISTBOX之間添加 刪除項
protected void btnadd_Click(object sender, EventArgs e)
{
if (this.LBadd.SelectedIndex == -1)
{
this.hidShowOnceMessage.Value = "請在左邊選擇要加入的架位";
return;
}
ListItemCollection Items = new ListItemCollection();
foreach (ListItem item in this.LBadd.Items)
{
if (item.Selected)
Items.Add(item);
}
for (int i = 0; i < Items.Count; i++)
{
ListItem item2 = this.LBdel.Items.FindByValue(Items[i].Value);
if (item2 == null)
{
this.LBdel.Items.Add(Items[i]);
this.LBadd.Items.Remove(Items[i]);
}
}
//foreach (ListItem item in this.LBadd.Items)
//{
// if (item.Selected)
// {
// //string sUsername = this.LBadd.item.Text.Trim();
// //string sUserid = this.LBadd.item.Value.Trim();
// ListItem item2 = this.LBdel.Items.FindByValue(item.Value);
// if (item2 == null)
// {
// this.LBadd.Items.Remove(item);
// //Items.Remove(item.Value);
// this.LBdel.Items.Add(item);
// //this.LBadd.Items.RemoveAt(i);
// //this.LBdel.Items.Add(new ListItem(sUsername, sUserid));
// }
// else
// {
// //this.hidShowOnceMessage.Value="該用戶已分配";
// return;
// }
// //this.LBadd.Items.Remove(item);
// }
//}
}
//protected void btnadd_Click(object sender, EventArgs e)
//{
// if (this.LBadd.SelectedIndex == -1)
// {
// this.hidShowOnceMessage.Value = "請在左邊選擇要加入的架位";
// return;
// }
// string sUsername = this.LBadd.SelectedItem.Text.Trim();
// string sUserid = this.LBadd.SelectedItem.Value.Trim();
// ListItem item = this.LBdel.Items.FindByValue(sUserid);
// if (item == null)
// {
// this.LBadd.Items.RemoveAt(this.LBadd.SelectedIndex);
// this.LBdel.Items.Add(new ListItem(sUsername, sUserid));
// }
// else
// {
// //this.hidShowOnceMessage.Value="該用戶已分配";
// return;
// }
//}
protected void btndel_Click(object sender, EventArgs e)
{
if (this.LBdel.SelectedIndex == -1)
{
this.hidShowOnceMessage.Value = "請在右邊選擇要加入的架位";
return;
}
ListItemCollection Items = new ListItemCollection();
foreach (ListItem item in this.LBdel.Items)
{
if (item.Selected)
Items.Add(item);
}
for (int i = 0; i < Items.Count; i++)
{
ListItem item2 = this.LBadd.Items.FindByValue(Items[i].Value);
if (item2 == null)
{
this.LBadd.Items.Add(Items[i]);
this.LBdel.Items.Remove(Items[i]);
}
}
}
//protected void btndel_Click(object sender, EventArgs e)
//{
// if (this.LBdel.SelectedIndex == -1)
// {
// this.hidShowOnceMessage.Value = "請在右邊選擇要加入的架位";
// return;
// }
// int index = this.LBdel.SelectedIndex;
// this.LBadd.Items.Add(this.LBdel.SelectedItem);
// this.LBadd.SelectedIndex = 0;
// this.LBdel.Items.RemoveAt(index);
// //int sn = CoolFuncs.Str2Int(ddlwhNO.SelectedValue);
// //init(sn);
//}