请参考以下代码 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(); } } }
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();
}
}
}
for(int i=0;i<list1.count;i++)
{
str+=list.Item[i].Text+";";
}
//Insert str to DataBase
那么用string.split就可以得到一个数组
ListBox的Items也是一个集合
这样不正好满足一个二维表结构么
剩下的自己也应该可以作出来了吧
可以说的具体点吗