Adding a JavaScript confirmation prompt to a delete command button in an ASP.NET grid view?

后端 未结 4 879
天命终不由人
天命终不由人 2021-01-28 10:34

So I have an ASP.NET grid view:



        
相关标签:
4条回答
  • 2021-01-28 10:58

    This is a javascript for delete confirmation.

     function not_check1()
                {
                  var where_to1= confirm("Do you really want to delete this record??");
    
                                        if (where_to1 == true)
                                            {
                                                return true;
                                            }
                                        else
                                            {
                                                return false;
                                            }
               }
    

    This is a gridview field from where you call the javascript.

     <asp:TemplateColumn ItemStyle-Width="20" >
    <ItemTemplate>
     <asp:ImageButton ID="ib_delete" runat="server" ImageUrl="~/image/images.jpg" commandName="Delete"  OnClientClick="return not_check1();" ImageAlign="Middle"/></ItemTemplate>
    
    </asp:TemplateColumn>
    
    0 讨论(0)
  • 2021-01-28 11:11

    When I've done this I've used a Template Field with the ConfirmButtonExtender from the Ajax Control Toolkit.

    <asp:TemplateField>
       <ItemTemplate>   
           <asp:Button name="DeleteButton" commandName="Delete" Text="Delete" runat="server" />   
           <ajaxToolkit:ConfirmButtonExtender TargetControlId="DeleteButton" ConfirmText="Delete this entry?" />
       </ItemTemplate>   
    </asp:TemplateField>  
    
    0 讨论(0)
  • 2021-01-28 11:12

    In RowDataBound add -

    LinkButton objDelete = e.Row.Cells[0].Controls[0] as LinkButton;
    objDelete.Attributes.Add("onclick", "javascript:return confirm('Do you want to delete this item?');");
    
    0 讨论(0)
  • 2021-01-28 11:22

    You could always use a TemplateField rather than the CommandField.

    <asp:TemplateField>
      <ItemTemplate>
        <asp:Button name="btnDelete" commandName="Delete" OnClientClick="return confirm('Delete 
    this Item');" Text="Delete" runat="server" />
        <asp:Button name="btnEdit" commandName="Edit" Text="Edit" runat="server" />
      </ItemTemplate>
    </asp:TemplateField>
    
    0 讨论(0)
提交回复
热议问题