Casting DataGridItem.DataItem to Object
Hi
I'm binding an array of objects to a datagrid. I then want to select a few of these items before proceeding to the next page.
My problem is that I can't cast the DataGridItem.DataItem from the datagrind into a custom type.
Here's the code:
// this is the datagrid
protected System.Web.UI.WebControls.DataGrid CollNoteResults;
// here's the array of my objects - CollNoteStatements
// inherits from ArrayList...
CollNoteStatements cnss = new CollNoteStatements();
// here's the databind
this.CollNoteResults.DataSource = cnss;
CollNoteResults.DataBind();
// here's the DataGridItem - it's in a loop with index i
DataGridItem dgi = (DataGridItem) CollNoteResults.Items[i];
// here's me trying to cast the DataItem out as a type
// this is where it starts to go wrong
CollNoteStatement cns = dgi.DataItem as CollNoteStatement;
Although there's no build error, the variable cns is simply not set (or set to null).
Please help someone?
Thanks
Tom
|