0

我在将选定的列表框项导出到数据表时遇到问题,我想将多个选定的植物导出到数据表中,你能帮忙吗?

   int numberofplants = 0;

        foreach (ListItem li in lbxPlants.Items)
        {
            if (li.Selected)
            {
                numberofplants++;
                DataTable dtplants = new DataTable();
                dtplants.Columns.Add("Plants");
                DataRow drplants = dtplants.NewRow();
                drplants[0] = li.Value;
                dtplants.Rows.Add(drplants);

            }
        }
4

1 回答 1

1
int numberofplants = 0;

DataTable dtplants = new DataTable();
dtplants.Columns.Add("Plants");

foreach (ListItem li in lbxPlants.Items)
{
    if (li.Selected)
    {
        numberofplants++;

        DataRow drplants = dtplants.NewRow();
        drplants[0] = li.Value;
        dtplants.Rows.Add(drplants);
    }
}
于 2012-10-04T08:46:30.533 回答