在gridview中删除时不会出现Javascript确认框

时间:2015-04-21 22:00:32

标签: c# asp.net

点击gridview中的删除链接按钮时,未显示确认框。我写这段代码,但我不知道为什么它不起作用......

<asp:GridView ID="gvwAuctionExport" runat="server" AutoGenerateColumns="false" OnRowCommand="gvwAuctionExport_RowCommand" OnRowDataBound="gvwAuctionExport_RowDataBound"  OnRowDeleting="gvwAuctionExport_RowDeleting">
<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <div class="btn-group btn-group-xs" id="bgroup">                                                                                 
                <asp:LinkButton ID="lnkInspectionDelete"  runat="server" Text="Delete" CssClass="btn btn-danger" CommandArgument='<%# Eval("inspection_id") %>' CommandName="Delete"></asp:LinkButton>
            </div>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="address" HeaderText="Address" />
    <asp:BoundField DataField="city" HeaderText="City" />
    <asp:BoundField DataField="state" HeaderText="State" />
</Columns>
</asp:GridView>
protected void gvwAuctionExport_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        int InspectionID = Convert.ToInt32(e.CommandArgument);
        string status = string.Empty;
        status = DACls.DeleteInspectionByID(InspectionID);
    }
}    
protected void gvwAuctionExport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton l = (LinkButton)e.Row.FindControl("lnkInspectionDelete");
            l.Attributes.Add("onclick", "javascript:return " +
            "confirm('Are you sure you want to delete this record");
        }
    }
protected void gvwAuctionExport_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    bindGridView();
}
public void bindGridView(){
        DataSet DS = new DataSet();
        SqlConnection DBCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
        SqlCommand Cmd = new SqlCommand("USP_Inspection_Export", DBCon);
        Cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter AHadp = new SqlDataAdapter(Cmd);
        AHadp.Fill(this.DS);
        DataTable dt = DS.Tables[0];
        this.gvwAuctionExport.DataSource = dt;
        this.gvwAuctionExport.DataBind();
}

当我点击删除按钮并从调试器检查时,它不会进入GridView RowDataBound函数范围。我不知道这里发生了什么?

0 个答案:

没有答案