我需要將集合綁定到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
肯定有很多記錄。我可能做錯了什麼?
噢。但是,那麼我是否需要該實體類上的構造函數 – cring
上面的語法不需要任何其他構造函數 – flq