62,268
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PersonsConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter MyAdapter = new SqlDataAdapter("select * from Persons", conn);
DataSet ds = new DataSet();
MyAdapter.Fill(ds);
ListBox1.DataSource = ds.Tables[0].DefaultView;//设定数据源
ListBox1.DataValueField = "worknum";//自己要传进的值
ListBox1.DataTextField = "name";//显示文本
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = ListBox1.Items.Count - 1; i >= 0; i--)
{
if (ListBox1.Items[i].Selected)
{
ListBox2.Items.Add(ListBox1.Items[i].Text.ToString());//添加项
ListBox2.Items[ListBox2.Items.Count - 1].Value = ListBox1.Items[i].Value;//对该项赋值
ListBox1.Items.RemoveAt(i);//根据索引进行删除
}
}
ListBox1.DataBind();
ListBox2.DataBind();
}
当转到第二个LIST中。顺序是反过来的。。你可以先记录。。然后再添加。。我想你应该可以做出来的。