asp.net - 访问 radGrid 列中的值

标签 asp.net telerik radgrid

我想访问 radGrid 控件中的值。鉴于下图,我想访问“Status”的值。但我似乎无法理解。

我收到一条错误消息

"Unable to cast object of type 'TripLeg' to type 'Telerik.Web.UI.GridDataItem'."

有什么想法如何访问该专栏吗?

GridItem

最佳答案

你就快到了。您只需转换 DataItem到适当的对象。假设您的数据源是 IEnumerable<TripLeg>

这是示例 -

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");
   }
}

关于asp.net - 访问 radGrid 列中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16491601/

相关文章:

asp.net - 单击 Radgrid 中的编辑按钮时不显示编辑表单

asp.net - RadGrid.Rebind() 和 RadGrid.MasterTableView.Rebind() 有什么区别?

asp.net - aspx 页面中出现错误消息 "String was not recognized as a valid Boolean"

asp.net - 固定宽度网站中的网格列过多

c# - Asp.net 2 与 Extjs 4 Grid CRUD 示例

c# - RadComboBox 展开时间长

c# - 从 json 中删除 xml 标签

asp.net-mvc - KendoUI 网格 Ajax 绑定(bind)参数选择

asp.net - 将生成后事件添加到Visual Studio 2008中的网站

asp.net - 重命名 ASP.NET session Cookie 名称的原因?