I'm trying to loop through rows and get their Indexes (Primary Keys from SQL). I'm getting a NRE on "this.SelectRowIndexes.Add(ResourceKey)" I can't figure out why it would matter and how can I fix this?
CODE:
private void GetIndexes()
{
List<int> SelectRowIndexes = new List<int>();
for (int i = 0; i < gridViewRecords.Rows.Count; i++)
{
DataRowView drv = (DataRowView)gridViewRecords.CurrentRow.DataBoundItem;
DataRow selectedRow = drv.Row;
ResourceKey = Convert.ToInt32(selectedRow["ResourceAndInstallKey"]);
this.SelectRowIndexes.Add(ResourceKey);
}
}
I also have it up in my class (this has been a ton of troubleshooting, so my code looks terrible)
public List<int> SelectRowIndexes { get; set; }
I had this prior. Several of the answers quoted this code. I changed mine because the if-else was actually used for something else, which has now been deleted
if (this.SelectRowIndexes == null)
{
this.SelectRowIndexes.Add(ResourceKey);
}
else
{
this.SelectRowIndexes.Add(ResourceKey);
}