Can't pass DataItem to DataRowView in custom binding script

I have an object that returns an IList that I am getting from my ObjectDataSource and binding to a Gridview. Everything works fine if I just use the standard binding, but I try to set up the binding to set properties on the linkbutton like this:

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 when I find e.Row.DataItem in DataRowView. The code above is from Matt Berseth from the awful blog on Virtual Earth ... that's what I'm trying to implement here. Any ideas?

0


source to share


1 answer


Set a breakpoint in the debugger and see what type e.Row.DataItem

it really is.



This will only DataRowView

be if the parameter DataSource

you are setting on the grid is DataView

or DataTable

. Otherwise, it will be the type of the collection item.

+2


source







All Articles