我有一个返回 IList 的对象,我从 ObjectDataSource 获取并绑定到 Gridview。如果我只使用标准绑定,一切正常,但我正在尝试自定义绑定以在链接按钮上设置属性,如下所示:
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"]);
}
}
我将 e.Row.DataItem 转换为 DataRowView 时发生错误。上面的代码来自 Matt Berseth 在 Virtual Earth 上的精彩博客……这就是我在这里尝试实现的。有任何想法吗?