I am new to ASP.NET and I recently discovered repeaters. Some people use them, others do not, and I'm not sure which solution would be best practice.
From what I experienced, it simplifies a simple job (displays a list), but as soon as you want to do more complex things, complexity explodes, logically wise.
Maybe only I and I poorly understand the concept (this is very possible), so here is an example of what I'm trying to do, and my problem:
Problem . I want to display a list of files located in a folder.
Decision
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 great.
New problem . I want to be able to delete these files.
Solution . I add a delete link to the element template:
<asp:LinkButton ID="lbFileDelete" runat="server" Text="delete" CommandName="delete" />
I will catch the event:
protected void repFiles_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "delete") {
... then what? How to get the path to the file that I want to delete here, knowing that e.Item.DataItem is null (I started the debugger).
Did I just spend my time using repeaters when I could do the same, using a loop that would be just as simple, just-not quick elegant?
What is the real advantage of using repeaters over other solutions?