要求是;listbox中每條數據要用分號隔開 插入到數據庫中 我是在是想不出來 清大家來幫幫忙

解决方案 »

  1.   

    请参考以下代码  
             private void addButton_Click(object sender, System.EventArgs e)
                {
                    // Add the items selected in ListBox1 to DataGrid1.
                    foreach (ListItem item in ListBox1.Items)
                    {
                        if (item.Selected)
                        {
                            // Add the item to the DataGrid.
                            // First, get the DataTable from the Session variable.
                            dt = (DataTable)Session["data"];

                            if (dt != null)
                            { 
                                // Create a new DataRow in the DataTable.
                                DataRow dr = dt.NewRow();
                                // Add the item to the new DataRow.
                                dr["Item"] = item.Text;
                                // Add the item's value to the DataRow.
                                dr["Price"] = item.Value;
                                // Add the DataRow to the DataTable.
                                dt.Rows.Add(dr);                            // Rebind the data to DataGrid1.
                                dv = new DataView(dt);
                                DataGrid1.DataSource = dv;
                                DataGrid1.DataBind();
                            }
                        }
                    }
      

  2.   

    string str;
    for(int i=0;i<list1.count;i++)
    {
       str+=list.Item[i].Text+";";
    }
    //Insert str to DataBase
      

  3.   

    分號隔開
    那么用string.split就可以得到一个数组
    ListBox的Items也是一个集合
    这样不正好满足一个二维表结构么
    剩下的自己也应该可以作出来了吧
      

  4.   

    greennetboy(我的老婆叫静静)
    可以说的具体点吗