How to bind a repeater to an array of a custom class? [closed]
I have a class like this
public class Link
{
public string LinkID { get; set; }
public string Title { 开发者_开发知识库get; set; }
public string URL { get; set; }
}
and a method that returns an array of Link[]
Could I bind that to a repeater, which will reference the Title and URL from Link?
How do I reference it?<%# DataBinder.Eval(Container.DataItem, "Title") %>
doesn't make anything show up
edit:This is embarrassing..I forgot that I emptied the database a couple days ago
Make sure you are setting your DataSource and then Binding:
YourRepeater.DataSource = GetArray();
YourRepeater.DataBind();
Once everything is bound, you can reference the items in your repeater:
<%# DataBinder.Eval( Container.DataItem, "Title" ) %>
or
<%# Eval( "Title" ) %>
assuming that your are properly binding your array of Link objects to the repeater, this should work:
<%# DataBinder.Eval(Container.DataItem, "Link.Title") %>
精彩评论