Click here to Skip to main content
16,004,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i m using image button in gridview for deletion and updation.
but its command event is not working...tell me plz for this i m using this code
XML
<asp:GridView ID="gv_allcontact" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="gv_appt_SelectedIndexChanged"
                                        Width="813px">
                                        <Columns>
                                            <asp:BoundField DataField="contact_calling_data" HeaderText="Calling Date" />
                                            <asp:BoundField DataField="contact_name" HeaderText="Name" />
                                            <asp:BoundField DataField="contact_company" HeaderText="Company Name" />
                                            <asp:BoundField DataField="contact_mobile1" HeaderText="Mobile Number" />
                                            <asp:BoundField DataField="contact_email" HeaderText="Email-Id" />
                                            <asp:BoundField DataField="contact_service_type" HeaderText="Service Type" />
                                            <asp:BoundField DataField="emp_name" HeaderText="Added By" />
                                            <asp:BoundField DataField="contact_clngstatus" HeaderText="Current Status" />
                                            <asp:TemplateField HeaderText="Status">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lbtn_allstatus" runat="server" CommandArgument='<%# Bind("contact_id") %>'
                                                        OnCommand="lbtn_allstatus_Command1">Status</asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Email">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lbtn_allemail" runat="server" OnCommand="lbtn_allemail_Command1"
                                                        CommandArgument='<%# Bind("contact_id") %>'>Email</asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="View">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lbtn_view_all" runat="server" CommandArgument='<%# Bind("contact_id") %>'
                                                        OnCommand="lbtn_view_all_Command">View</asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Edit">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="lbtn_editall" runat="server" CommandArgument='<%# Bind("contact_id") %>'
                                                        OnCommand="lbtn_editall_Command1" ImageUrl="~/images/imagesedit.jpg" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Delete">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="lbtn_delall" runat="server" CausesValidation="False" CommandArgument='<%# Bind("contact_id") %>'
                                                        OnClientClick="return confirm('Do you want to delete this record')"
                                                        OnCommand="lbtn_delall_Command1" ImageUrl="~/images/delete iamge.jpg" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>




and the code on code behind is as follows:->
C#
protected void lbtn_editall_Command1(object sender, CommandEventArgs e)
   {
       object id = e.CommandArgument;
       id1 = Convert.ToInt32(id);
       getpermissionCode();
       if (Session["username"].ToString() == code)
       {
           Response.Redirect("EditContact.aspx?id=" + id);
       }
       else if (Session["type"].ToString() == "CA" || Session["type"].ToString() == "BA")
       {
           Response.Redirect("EditContact.aspx?id=" + id);
       }
       else
       {
           ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "<script>alert('You Do Not Have Permissions To Edit This');</script>", false);
       }
   }
Posted
Updated 27-Nov-11 18:49pm
v2

1 solution

Write your code under gv_allcontact_RowCommand event in gridview.
give CommandName="imgBtn1" attribute in ASPX.

check following code.
C#
protected void gv_allcontact_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandName == "imgBtn1")
Response.Write("imagebutton clicked");

}


Do not forget to write !isPostBack in pageload. and bind your gridview under !isPostBack
 
Share this answer
 
Comments
Member 8387468 28-Nov-11 1:10am    
thnx

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