如何将值从一个列表框移到另一个列表框? [英] How to shift a value from one listbox to another listbox?

查看:82
本文介绍了如何将值从一个列表框移到另一个列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我想将值从一个列表框移动到另一个列表中.我成功地将值从一个列表框移动到另一个列表中,但问题是当我运行代码时列表框为空.我以前的值不是显示在列表框中.
请提出我做错了的事情.
我的代码是:

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:

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);
    }
}


推荐答案

为您的Web应用程序使用循环语句,并使用按钮将您的项目注册到另一个列表框中.

循环语句必须在按钮button_click中
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


HI,

请参考此

如何将列表框项目移动到另一个C#中的列表框. [


REFER THIS

How to Move List Box Items to another List Box in C#.[^]


这篇关于如何将值从一个列表框移到另一个列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆