简体   繁体   English

使用方法在asp:repeater中获取价值

[英]Use method to get value in asp:repeater

When I loop through my data in c# I have to use the below to get the value: 当我在C#中遍历数据时,我必须使用以下方法获取值:

foreach (var item in documentQuery)
{
   string value = item.getproperty("title");
  //value = "hello world"
}

But if I want to bind the results to an asp:repeater in an ASPX page how would I call this same getproperty method in the ItemTemplate? 但是,如果我想将结果绑定到ASPX页面中的asp:repeater,我如何在ItemTemplate中调用相同的getproperty方法? Because if I just go <%# Eval("title") %> it gives an error... 因为如果我只是去<%#Eval(“ title”)%>,它将给出一个错误...

Eval() is a shortcut to simplify binding. Eval()是简化绑定的快捷方式。 To do something more complex, you won't be able to use it. 要做更复杂的事情,您将无法使用它。

I think you need to do something like: 我认为您需要执行以下操作:

<%# Container.DataItem.getproperty("title")) %>

Or you might have to cast Container.DataItem to your specific type of item: 或者,您可能必须将Container.DataItem强制转换为特定的项目类型:

<%# (Container.DataItem as XXXXXXX).getproperty("title")) %>

where XXXXXXX is whatever the type your item is. XXXXXXX是您项目的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM