I'm having trouble replicating this code for a DataList object (as opposed to a DataGrid).
(where groupRecipients is a DataGrid object)
The variable row (of type DataListItem) in the code I'm attempting to write has no Cells property, because of this I'm having to re-write all the code to do the conversion from DataGrid to DataList.
The problem occurs where I attempt to retrieve a value from one of the row cells.
The reason for this is that I keep getting an "object reference not set to instance of object" error when I try to use code like that suggested on MSDN, ie :
Debugging seems to suggest that singleRecipients.Items.DataItem is returning a null reference (where singleRecipients is my DataList object). This explains the exception I'm receiving, but I can't figure out why.
This code will fire on a Button click event (not related to the DataList, so no DataListEventArgs are available for use).
(where groupRecipients is a DataGrid object)
Code:
string arbitraryStringValue = String.Empty;
foreach (DataGridItem row in groupRecipients.Items) {
arbitraryStringValue = row.Cells[3].Text;
}
The variable row (of type DataListItem) in the code I'm attempting to write has no Cells property, because of this I'm having to re-write all the code to do the conversion from DataGrid to DataList.
The problem occurs where I attempt to retrieve a value from one of the row cells.
The reason for this is that I keep getting an "object reference not set to instance of object" error when I try to use code like that suggested on MSDN, ie :
Code:
Double Price = Convert.ToDouble(((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString());
Debugging seems to suggest that singleRecipients.Items.DataItem is returning a null reference (where singleRecipients is my DataList object). This explains the exception I'm receiving, but I can't figure out why.
This code will fire on a Button click event (not related to the DataList, so no DataListEventArgs are available for use).