Thursday 1 July 2010

Anonymous Types in a RowDataBound event

Using Linq to SQL to populate a grid

protected void ConsignmentGridView_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var o = e.Row.DataItem;
Type t = o.GetType();
PropertyInfo pi = t.GetProperty("ConsignmentID");
long ConsignmentID = (long)pi.GetValue(o, null);