I have an object that returns an IList which I'm getting from my ObjectDataSource and binding to a Gridview. All works fine if I just use standard binding, but I'm trying to customize my binding to set properties on a linkbutton as follows:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// extract the link button
LinkButton lnkViewMap = (LinkButton)e.Row.FindControl("lnkViewMap");
// grab the datarowview
System.Data.DataRowView row = (System.Data.DataRowView)e.Row.DataItem;
// set the onclientclick to fire our showMap javascript function,
// passing through the lat/longs
lnkViewMap.OnClientClick = string.Format("showMap({0}, {1}); return false;", row["Lat"], row["Long"]);
}
}
My error occurs where I am casting the e.Row.DataItem to a DataRowView. The code above is from Matt Berseth's awesome blog on Virtual Earth...which is what I am trying to implement here. Any ideas?