Gridview linkbutton事件未触发

时间:2014-06-24 09:14:30

标签: c# javascript jquery asp.net gridview

我正在开发一个asp.net应用程序,我有一个像这样的删除图像按钮:

<asp:GridView ID="grdPaymethods" runat="server" ShowHeader="False" GridLines="None" AutoGenerateColumns="False" OnRowDataBound="grdPaymethods_RowDataBound" OnRowDeleting="grdPaymethods_RowDeleting">
    <asp:TemplateField ShowHeader="False">
        <ItemTemplate>
            <Columns>
                <asp:ImageButton ID="IBtnDelete" runat="server" ToolTip="Click to delete"
                                CommandArgument='<%# Eval("MethodId") %>'
                                OnClientClick="javascript:return deleteItem(this.name, this.alt);"
                                ImageUrl="~/Images/Delete.png" AlternateText='<%# Eval("MethodId") %>'
                                CommandName="Delete" />
        </ItemTemplate>
    </asp:TemplateField>

我看到行删除事件被触发。但我想使用linkbutton而不是图像按钮。所以我使用了这段代码:

   <asp:LinkButton ID="IBtnDelete1" runat="server" ToolTip="Click to delete" 
                                CommandArgument='<%# Eval("MethodId") %>'
                                OnClientClick="javascript:return deleteItem(this.name, this.alt);"
                                Text="Delete" AlternateText='<%# Eval("MethodId") %>'
                                CommandName="Delete"></asp:LinkButton>

显示链接按钮,但点击链接按钮只刷新页面并且不调用行删除事件。我在点击事件上尝试了OnRowCommand =“grdPaymethods_RowCommand”事件和链接按钮,但它们没有被触发,页面只是刷新。

这里是js函数:

 function deleteItem(uniqueID, itemID) {
            e.preventDefault();
            var dialogTitle = 'Permanently Delete Item ' + itemID + '?';

            $("#deleteConfirmationDialog").html('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Please click delete to confirm deletion.</p>');

            $("#deleteConfirmationDialog").dialog({
                title: dialogTitle,
                buttons: {
                    "Delete": function () {
                        __doPostBack(uniqueID, '');
                        $(this).dialog("close");
                    },
                    "Cancel": function () { $(this).dialog("close"); }
                }
            });

            $('#deleteConfirmationDialog').dialog('open');
            return false;
        }



  $(function () {
            InitializeDeleteConfirmation();
        });

        function InitializeDeleteConfirmation() {
            $('#deleteConfirmationDialog').dialog({
                autoOpen: false,
                resizable: false,
                height: 140,
                modal: true,
                buttons: {
                    "Delete": function () {
                        $(this).dialog("close");
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }

                }
            });
        }

和行删除事件:

protected void grdPaymethods_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // cancel the automatic delete action
            e.Cancel = true;

            // do the delete
           // _categoryResposite.DeleteCategories(Convert.ToInt32(e.id));


            grdPaymethods.DataSource = customer.PaymentMethods.OrderByDescending(a => a.Preferred);
            grdPaymethods.DataBind();


        }

请建议解决方案。

0 个答案:

没有答案
相关问题