views:

231

answers:

2

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:

<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?

+2  A: 
<%#((Person)Container.DataItem).Thing()%>
Mehrdad Afshari
+1  A: 

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. While you can call a function from here, I think it would be better design to use a property.

Mark Brittingham
I can't just "use a property" - the code I posted was simplified in the interests of making the question clear. In reality, changing the method to a property is not a viable option.
kristian
Ok - just trying to be helpful as this is, generally, the preferred route. Good luck with the remainder of you problem.
Mark Brittingham