ho provato pure in questo modo e mi sembra che funzioni. vuoi provare?
codice:
private void Page_Load(object sender, System.EventArgs e)
{
// Inserire qui il codice utente necessario per inizializzare la pagina.
if(!this.IsPostBack) carica();
}
void carica()
{
this.ListBox1.Items.Add(new ListItem("rosso","rosso"));
this.ListBox1.Items.Add(new ListItem("verde","verde"));
this.ListBox1.Items.Add(new ListItem("blu","blu"));
this.ListBox1.Items.Add(new ListItem("giallo","giallo"));
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{ // >
foreach(System.Web.UI.WebControls.ListItem item in this.ListBox1.Items)
{
if(item.Selected)
{
item.Selected = false;
this.ListBox1.Items.Remove(item);
this.ListBox2.Items.Add(item);
LinkButton1_Click(null, null);
break;
}
}
}
private void LinkButton2_Click(object sender, System.EventArgs e)
{ // >>
foreach(System.Web.UI.WebControls.ListItem item in this.ListBox1.Items)
this.ListBox2.Items.Add(item);
this.ListBox1.Items.Clear();
}
private void LinkButton3_Click(object sender, System.EventArgs e)
{ // <
foreach(System.Web.UI.WebControls.ListItem item in this.ListBox2.Items)
{
if(item.Selected)
{
item.Selected = false;
this.ListBox2.Items.Remove(item);
this.ListBox1.Items.Add(item);
LinkButton3_Click(null, null);
break;
}
}
}
private void LinkButton4_Click(object sender, System.EventArgs e)
{ // <<
foreach(System.Web.UI.WebControls.ListItem item in this.ListBox2.Items)
this.ListBox1.Items.Add(item);
this.ListBox2.Items.Clear();
}