简体   繁体   English

删除转发器中的用户控件

[英]remove a user control in repeater

I have a control image in a user control. 我在用户控件中有一个控件图像。 And I'm using a repeater to create several images list. 我正在使用中继器来创建多个图像列表。

I have a button outside from the user control to delete image (per images). 我在用户控件外部有一个按钮,用于删除图像(每个图像)。

I want to know, how can I make references to an specific row when I click in the button to delete the image. 我想知道,当我单击按钮删除图像时,如何引用特定行。

This is the repetear: 这是重复的:

<asp:Repeater ID="ImageRepeater" runat="server" 
    onitemcommand="ImageRepeater_ItemCommand">
    <ItemTemplate>
        <div>
            <uc1:IVT_DisplayImage ID="IVT_DisplayImage1" runat="server" ImageURL="<%# Container.DataItem %>" />
            <asp:Button ID="RemoveDiplayImage" Text="Remove" runat="server" 
            CommandName="delete" 
            />
        </div>
    </ItemTemplate>
</asp:Repeater>

This is the event ItemCommand: 这是事件ItemCommand:

protected void ImageRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "delete")
    {
        //????
    }
}

I want to know, how identify by code wich row (user control) I'm selecting. 我想知道,如何通过代码选择行(用户控件)进行标识。

You need to add CommandArgument to your button like CommandArgument="<%# Container.ItemIndex %>" . 您需要像CommandArgument="<%# Container.ItemIndex %>"这样将CommandArgument添加到您的按钮。

This way, in the code; 这样,在代码中; e.CommandArgument gives you the item number, with which you can get the item that you want. e.CommandArgument提供了商品编号,您可以使用该编号获取所需的商品。

Note: In fact instead of specifying ItemIndex as CommandArgument , you can use any Primary Key (Unique Identifier) from the DataSource that you bind to the repeater from where you will be able to get hold of the record directly from the list object (DataSource). 注意:实际上,不必将ItemIndex指定为CommandArgument ,而可以使用绑定到转发器的数据源中的任何主键(唯一标识符),从中可以直接从列表对象(数据源)获取记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM