I’m trying to render out some images on an aspx page.
Error I’m getting in the code below is: DataBinding: ‘_Default+ImageThing’ does not contain a property with the name ‘FileName’.
public class ImageThing
{
public string FileName;
}
private void DisplayThumbnailImages()
{
ImageThing imageThing1 = new ImageThing();
ImageThing imageThing2 = new ImageThing();
imageThing1.FileName = "asdf.jpg";
imageThing2.FileName = "aaa.jpg";
List<ImageThing> imagesToRender = new List<ImageThing>();
imagesToRender.Add(imageThing1);
imagesToRender.Add(imageThing2);
Repeater1.DataSource = imagesToRender;
Repeater1.DataBind();
}
here is the aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "FileName")%>
</ItemTemplate>
</asp:Repeater>
Thanks
The data binding syntax does not work with fields, it only works with properties. Try making this change to your ImageThing class:
Now it’s a property and now you should be able to access is via the template using <%#DataBinder.Eval(Container.DataItem, “FileName”)%> (or even better, just <%# Eval(“FileName”) %>).
Happy Programming!