I am fairly new to ASP.NET and I discovered repeaters recently. Some people use them, other don't and I'm not sure which solution would be the best practice.
From what I've experienced, it makes simple operation (display a list) simple, but as soon as you want to do more complicated things the complexity explodes, logic wise.
Maybe it's just me and me poor understanding of the concept (this is highly possible), so here's an example of what am I trying to do and my issue:
Problem: I want to display a list of files located in a folder.
Solution:
String fileDirectory = Server.MapPath("/public/uploaded_files/");
String[] files = Directory.GetFiles(fileDirectory);
repFiles.DataSource = files;
repFiles.DataBind();
and
<asp:Repeater ID="repFiles" runat="server" OnItemCommand="repFiles_ItemCommand" >
<ItemTemplate>
<a href="/public/uploaded_files/<%# System.IO.Path.GetFileName((string)Container.DataItem) %>" target="_blank">View in a new window</a>
<br />
</ItemTemplate>
</asp:Repeater>
This works fine.
New problem: I want to be able to delete those files.
Solution: I add a delete link in the item template:
<asp:LinkButton ID="lbFileDelete" runat="server" Text="delete" CommandName="delete" />
I catch the event:
protected void repFiles_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delete")
{
// ... blah
}
}
... then what? How do I get the file path that I want to remove from here knowing that e.Item.DataItem is null (I ran the debugger).
Did I just wasted my time using repeaters when I could have done the same thing using an loop, which would have been just as simple, just -maybe- less elegant?
What is the real advantage of using repeaters over other solutions?