如何访问在ASP.NET直放站ItemDataBound事件的数据源字段? [英] How to access datasource fields in an ASP.NET Repeaters ItemDataBound event?

查看:152
本文介绍了如何访问在ASP.NET直放站ItemDataBound事件的数据源字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被绑定到LINQ查询的结果Repeater控件。

I have a Repeater control that is being bound to the result of a Linq query.

我想在ItemDataBound事件的数据源的领域之一的价值,但我不知道如何做到这一点。

I want to get the value of one of the datasource's fields in the ItemDataBound event, but I'm not sure how to do this.

推荐答案

您可以使用: e.Item.DataItem

例如:<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx\">Repeater.ItemDataBound事件

// This event is raised for the header, the footer, separators, and items.
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
  // Execute the following logic for Items and Alternating Items.
  if (e.Item.ItemType == ListItemType.Item ||
      e.Item.ItemType == ListItemType.AlternatingItem)
  {
    if (((Evaluation)e.Item.DataItem).Rating == "Good")
    {
      ((Label)e.Item.FindControl("RatingLabel")).Text= "<b>***Good***</b>";
    }
  }
} 

这篇关于如何访问在ASP.NET直放站ItemDataBound事件的数据源字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆