You are almost there. You just need to apply the DataItem to the corresponding object. Suppose your data source is IEnumerable<TripLeg> .
Here is an example -
if (e.Item is GridDataItem) { var item = e.Item as GridDataItem; var tripLeg = e.Item.DataItem as TripLeg; // Cast to appropriate object var status = tripLeg.Status; // var hLink = (HyperLink) item.FindControl("HyperLink1"); // Above code will throw exception if the control is not found. var hLink = item.FindControl("XXXXX") as HyperLink; if(hLink != null) { hLink.Attributes.Add("XXXXX", "XXXXX"); } }
source share