我正在尝试将数据绑定到checkboxlist并得到以下错误:
数据源是无效类型。它必须是IListSource, IEnumerable,或IDataSource。
我使用的代码是:
for(var day = fromdate; day.Date <= todate; day = day.AddDays(1))
{
LeaveDtl.DataSource = day;
LeaveDtl.DataBind ();
}
答案 0 :(得分:0)
如果要在循环中添加单个项目,请执行以下操作:
for (var day = fromdate; day.Date <= todate; day = day.AddDays(1))
{
LeaveDtl.Items.Insert(LeaveDtl.Items.Count, new ListItem(day.ToShortDateString(), day.ToShortDateString()));
}