我将选定的listboxitems导出到数据表时遇到问题,我希望将多个选定的工厂导出到数据表中,您能帮忙吗?
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);
}
}
答案 0 :(得分: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);
}
}