我有一个转发器控件来显示图像。在每张图片下方,我都放置了一个用于删除图像的按钮。我希望在按下删除按钮时从转发器控件中删除图像。我到处尝试找到这个,但我没有得到解决方案。提前致谢。 这是我的代码:
<asp:Repeater ID="FileRepeater" runat="server" OnItemCommand="RepeaterCommand">
<ItemTemplate>
<div style="float: left; overflow: hidden; display: inline-block;">
<asp:Image ID="Image1" runat="server" Style="height: 200px; width: 200px; border: 1px solid gray;" ImageUrl="<%# Container.DataItem %>" />
<br />
<asp:Button ID="btnDelete" runat="server" Width="80px" Text="Delete" CommandName="delete" UseSubmitBehavior="false" />
</div>
</ItemTemplate>
</asp:Repeater>
protected void RepeaterCommand(object source, RepeaterCommandEventArgs e)
{
RepeaterItem itemToRemove = e.Item;
String sessionItemToRemove = itemToRemove.ToString();
Console.WriteLine("%c", sessionItemToRemove);
Session.Remove(sessionItemToRemove);
}
protected void Page_Load(object sender, EventArgs e)
{
string[] list = Directory.GetFiles(Server.MapPath("images"));
List<String> images = new List<string>(list.Count());
foreach (string item in list)
{
images.Add(String.Format("~/Images/{0}", System.IO.Path.GetFileName(item)));
}
FileRepeater.DataSource = images;
FileRepeater.DataBind();
}