问题与gridview中的imagebutton有关,即命令事件不起作用. [英] problem is related to imagebutton in the gridview thats command event is not working..

查看:70
本文介绍了问题与gridview中的imagebutton有关,即命令事件不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gridview中的图像按钮进行删除和更新.
但它的命令事件不起作用...请告诉我,我正在使用此代码

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

<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:->

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);
       }
   }

推荐答案

在gridview的 gv_allcontact_RowCommand 事件下编写代码.
在ASPX中提供 CommandName ="imgBtn1" 属性.

检查以下代码.
Write your code under gv_allcontact_RowCommand event in gridview.
give CommandName="imgBtn1" attribute in ASPX.

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

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

}



不要忘记在页面加载中编写!isPostBack .并将您的gridview绑定在!isPostBack



Do not forget to write !isPostBack in pageload. and bind your gridview under !isPostBack


这篇关于问题与gridview中的imagebutton有关,即命令事件不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆