Click here to Skip to main content
15,077,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a webpage in which i want to move value from one listbox to another.I am successful to moving value from one listbox to another but the problem is when i run the code then listbox is empty.My previous value is not shown in the listbox.
Please suggest something where i have done mistake.
My code is:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Move_value_from_one_listbox_to_another_listbox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { }
    }
    protected void button1_Click(object sender, EventArgs e)
    {
        if (Textbox1.Text == "")
        {
            return;
        
        }
        ListItem item = new ListItem();
        item.Value = Textbox1.Text;
        item.Text = Textbox1.Text;
        listbox1.Items.Add(item);
        Textbox1.Text = "";
    }
    protected void Buttonfrom_Click(object sender, EventArgs e)
    {
        //if (Listboxto.SelectedIndex == -1)
        //{
        //    return;
        //}
        ListItem item = new ListItem();
        item.Value = Listboxto.SelectedItem.Value;
        item.Text = Listboxto.SelectedItem.Text;
        listbox1.Items.Add(item);
        Listboxto.Items.Remove(item);

    }
    protected void buttonto_Click(object sender, EventArgs e)
    {
        if (listbox1.SelectedIndex == -1)
        {
            return;
        }
        ListItem item = new ListItem();
        item.Value = listbox1.SelectedItem.Value;
        item.Text = listbox1.SelectedItem.Text;
        Listboxto.Items.Add(item);
        listbox1.Items.Remove(item);
    }
}

Thanks!!
Posted
Updated 20-Aug-12 19:25pm
v3
Comments
   
There are many ways to screw up even such a simple thing. So, it's not possible to figure out how exactly you screw it up. How about some minimal code sample? Use "Improve question".
--SA

use a looping statement for your web application and use a button to enlist your items to another list box.

looping statements must be inside the function button_click
   
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900