Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataList / DataListItem question

Status
Not open for further replies.

nooro

Programmer
Feb 7, 2003
22
GB
I'm having trouble replicating this code for a DataList object (as opposed to a DataGrid).

(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).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top