请问一下,我用listbox1控件绑定数据库中三列字段,在listbox中显示3列(分别是院系,层次,专业)然后把我需要的行移到另外一个listbox2,现在我想把listbox2中的第三列即(专业)所有数据赋给一个lable....请问我该怎么做呢???
说得有点乱有人能解决吗??listbox1数据:             listbox2数据:
院系  层次  专业           院系  层次  专业  
11     12    13            11     12    13
21     22    23            21     22    23 
21     22    23
31     32    33
41     42    43然后把
listbox2中的第三列即(专业)13,23绑定到lable中。
是C#的。

解决方案 »

  1.   

    请问怎么把多个数据绑定到一个Label中?
      

  2.   

    把读取出来的数据 用字符串拼接下 
    然后赋给label.Text
      

  3.   

     public static string str="";
     public static string Allstr = "";int count = listbox2.SelectedItems .Count ;
                for (int i = 0; i < count ; i++)
                {
                    Allstr = str + this.listbox2.SelectedItems[i].ToString().Trim();
                    str = Allstr;
                }
                this.label1.Text = Allstr;
                str = "";
                Allstr = "
    但是这样是把listbox2三列内容都显示出来了,怎样才能把第三列显示出来呢
      

  4.   

    foreach(ListItem item in this.ListBox1.Items) 
       {
         Label1.Text+=item.Text+",";
       }  
      

  5.   

    你的listbox2是怎么绑定数据的
      

  6.   

    listbox2的数据时从listbox1中移过来的,listbox1绑定数据库但是listbox2得不是。。
      

  7.   

    foreach(ListItem item in this.ListBox1.Items) 
    {
    Label1.Text+=item.Text+",";
    }
    这个能绑定其中的一列吗?
      

  8.   

    listbox可以绑定三列啊,
     for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lst_DaiXuan_ZhuanYe.Items.Add(dt.Rows[i][0].ToString() + "--" + dt.Rows[i][1].ToString() + "--" + dt.Rows[i][2].ToString());
                }
      

  9.   


    那你直接把dt.Rows[i][2].ToString()拼接起来再赋给label不就可以了?
      

  10.   

    问题是listbox2的数据不是绑定数据库的,可以这样拼接么?。不太懂
    我试过如果listbox是连接数据库数据时可以像你这样做,但是如果不连接数据库数据的话,好像就。。
      

  11.   


    改成这个试试。。            string str = "";
                string Allstr = "";            for (int i = 0; i < listBox2.SelectedItems.Count; i++)
                {
                    str = listBox2.SelectedItems[i].ToString();
                    int lastIndex = str.LastIndexOf("--") + 2;
                    Allstr += str.Substring(lastIndex, str.Length - lastIndex);
                }
                label1.Text = Allstr;
      

  12.   

    luols:你的办法可以,我测试过了,数据出来了。
    太感谢你了谢谢。