[英]Binding a DataList to an object's method instead of a property
I have a class that looks like this: 我有一个看起来像这样的课程:
public class Person
{
public string Name { get; set; }
public string Thing() {
...
}
...
}
If I have an IList<Person>
that I'm using as a data source for a DataList control, and the DataList looks like this: 如果我有一个
IList<Person>
,我将其用作DataList控件的数据源,并且DataList如下所示:
<asp:DataList runat="server" RepeatColumns="1" ID="Profiles">
<ItemTemplate>
<%#Eval("Name") %>
</ItemTemplate>
</asp:DataList>
How do I replace the Name
property of the data source with a call to the data source object's Thing()
method? 如何通过调用数据源对象的
Thing()
方法替换数据源的Name
属性?
<%#((Person)Container.DataItem).Thing()%>
Use properties. 使用属性。 The property will be "Name" (or whatever) and the "Getter" on this property will be the method you wish to use to generate the value.
该属性将为“Name”(或其他),此属性上的“Getter”将是您希望用于生成值的方法。 While you can call a function from here, I think it would be better design to use a property.
虽然你可以从这里调用一个函数,但我认为使用属性会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.