Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a repeater control on my page with an image(img) control ,hyperlink control and an image(imgdelete) control
in different .
On hover of that hyperlink i have made the image (imgdelete) control as visible.
I want to add an onclick event to that (imgdelete) and on that click i want to delete the entire row in that repeater.


how can i go ahead??

my code is as follows:
<pre lang="xml"><als:Repeater ID="rptAttachmentNew" runat="server" OnItemDataBound="rptAttachmentNew_ItemDataBound">
                                           <HeaderTemplate>
                                               <table>
                                           </HeaderTemplate>
                                           <ItemTemplate>
                                               <tr>
                                                   <td>
                                                       <als:Image runat="server" ID="img" />
                                                   </td>
                                                   <td>
                                                       <div id="divAttachment">
                                                           <als:HyperLink runat="server" ID="hyperLink" Text='<%#Eval("Attachment Name") %>'
                                                               NavigateUrl='<%#Eval("File Path") %>' Target="_blank"></als:HyperLink>
                                                           <als:Image runat="server" ID="imgDelete" CssClass="hide" />
                                                       </div>
                                                   </td>
                                               </tr>
                                           </ItemTemplate>
                                           <AlternatingItemTemplate>
                                               <tr>
                                                   <td>
                                                       <als:Image runat="server" ID="img" />
                                                   </td>
                                                   <td>
                                                       <als:HyperLink runat="server" ID="hyperLink" Text='<%#Eval("Attachment Name") %>'
                                                           NavigateUrl='<%#Eval("File Path") %>' Target="_blank"></als:HyperLink>
                                                   </td>
                                                   <td>
                                                       <als:Image runat="server" ID="imgDelete" CssClass="hide" />
                                                   </td>
                                               </tr>
                                           </AlternatingItemTemplate>
                                           <FooterTemplate>
                                               </table>
                                           </FooterTemplate>
                                       </als:Repeater></pre>
Posted

1 solution

Try this

Attach event for Repeater

onitemcommand="rptAttachmentNew_ItemCommand"


Add Command Name and Argument for the Image control

<asp:image runat="server" commandname="delete" commandargument='<%#Eval("Id")%>' id="imgDelete" xmlns:asp="#unknown" />


Handle the event in code behind

protected void rptAttachmentNew_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "delete")
    {
        int id = Convert.ToInt(e.CommandArgument);
	//use the id for the delete logic
    }
}


Hope this helps...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900