Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a repeater in which i have two imagebuttons,
one for edit & other for delete the record.

But unfortunately both are not firing up Onclick event.

Even i have created this repeater from scratch many times.

and i have tried changing the event name in 'onclick' then it throws the error
CS1061: 'ASP.sim_aspx' does not contain a definition for 'btnEdit_Click1' and no extension method 'btnEdit_Click1' accepting a first argument of type 'ASP.sim_aspx' could be found (are you missing a using directive or an assembly reference?)


Repeater
<asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table class="addgrid" width="100%">
                        <thead>
                            <tr style="background-image: removed('NewTheam/images/Background.png'); height: 30px;
                                color: Black; vertical-align: middle;">
                                <td style="width: 50px;">
                                    S.No.
                                </td>
                                <td>
                                    Mobile#
                                </td>
                                <td>
                                    User
                                </td>
                                <td>
                                    Department
                                </td>
                                <td>
                                    Assigned
                                </td>
                                <td>
                                    Short#
                                </td>
                                <td>
                                    Cr.limit
                                </td>
                                <td>
                                    Account#
                                </td>
                                <td>
                                    Action
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            
                                <%# Container.ItemIndex + 1 %>
                        </td>
                        <td>
                            <%# Eval("MobileNo") %>
                        </td>
                        <td>
                            <%# Eval("Name") %>
                        </td>
                        <td>
                            <%# Eval("Department") %>
                        </td>
                        <td>
                            <%# Eval("AssignDate") %>
                        </td>
                        <td>
                            <%# Eval("ShortNo") %>
                        </td>
                        <td>
                            <%# Eval("CreditLimit") %>
                        </td>
                        <td>
                            <%# Eval("AccountNo") %>
                        </td>
                        <td>
                            <center>
                                <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="~/NewTheam/images/Edit.png"
                                    Width="20" Height="20" CommandArgument='<%# Eval("MobileNo") %>' OnClick="btnEdit_Click" />  
                                <asp:ImageButton ID="btnDel1" runat="server" ImageUrl="~/NewTheam/images/Bin.png"
                                    Width="20" Height="20" CommandArgument='<%# Eval("MobileNo") %>' OnClick="btndel_Click" />  
                            </center>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </tbody> </table>
                </FooterTemplate>
            </asp:Repeater>


Events
  protected void btnEdit_Click(object sender, EventArgs e)
        {
            string i = ((ImageButton)(sender)).CommandArgument.ToString();
            Response.Redirect("updateSIM.aspx?SIMCODE=" + i);
        }
<br />
        protected void btndel_Click(object sender, EventArgs e)
        {
            string i = ((ImageButton)(sender)).CommandArgument.ToString();
            Response.Redirect("del.aspx?SIMCODE=" + i + "&DOIF=" + 7);
        }


Guys is there any issue in the coding or what...

Please help me guys, i'm stuck from two days....

Thanks
Posted
Updated 11-Feb-15 2:58am
v3

refer : https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagebutton.commandargument(v=vs.110).aspx[^]
give command name, command argument and OnCommand event correctly, check the example code in the documentation

sample code:
ASP.NET
<asp:Repeater ID="myRepeater" runat="server" OnItemCommand="myRepeater_ItemCommand">
    <ItemTemplate>
        <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="edit-icon.png" CommandArgument='<%#Eval("MobileNo")%>' />
    </ItemTemplate>
</asp:Repeater>


C# code

C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            myRepeater.DataSource = new List<User>() { new User() { MobileNo = "3223234234" } };
            myRepeater.DataBind();
        }
    }

    protected void myRepeater_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
    {
        string Mobileno = ((ImageButton)e.CommandSource).CommandArgument;

    }
}
public class User
{
    public string MobileNo { get; set; }
}
 
Share this answer
 
v2
Comments
abdul subhan mohammed 11-Feb-15 10:08am    
outside of the repeater its working but inside the repeater its not working...
this imagebutton is in itemtemplate of the repeater but not in header or footer
DamithSL 11-Feb-15 10:46am    
check my update answer with sample code
[no name] 11-Feb-15 17:09pm    
+5
 
Share this answer
 
Comments
abdul subhan mohammed 11-Feb-15 8:26am    
i have tried all these but still i'm not able not get button event...
Avik Ghosh22 11-Feb-15 11:05am    
Please share your problem..

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