【发布时间】:2011-08-29 18:06:34
【问题描述】:
我需要根据用户选择的报告类型将集合绑定到 GridView。
每个报告略有不同,但使用相同的基本结果集,其中包含许多列。在绑定之前,我想遍历结果集并复制到一个更简单的集合(3 个字符串变量,分别称为“column1”、“column2”、“column3”)。
代码:
namespace etc.etc.etc
{
public class ReportEntity
{
public string column1 { get; set; }
public string column2 { get; set; }
public string column3 { get; set; }
}
}
List<ReportEntity> a = new List<ReportEntity>();
ReportEntity[] b = new ReportEntity[results.Length];
for (int i = 0; i < results.Length; i++)
{
//a[i].column1 = results[i].class.desc;
//a[i].column2 = results[i].student.firstname;
//a[i].column3 = results[i].timescanned.ToString();
//b[i].column1 = results[i].class.desc;
//b[i].column2 = results[i].student.firstname;
//b[i].column3 = results[i].timescanned.ToString();
}
取消注释我为a 设置值的位置会得到Index was out of range. Must be non-negative and less than the size of the collection.。
取消注释我为b 设置值的位置会给出Object reference not set to an instance of an object.。
results肯定有很多记录。我可能做错了什么?
【问题讨论】:
标签: c# collections