When asp. net realizes deleting the record of DataGrid a prompt message will pop up

  • 2021-01-02 21:48:25
  • OfStack

The example of this paper shows the method of asp. net to delete the record of DataGrid when the prompt message pops up, which is very practical in project development. The specific steps are as follows:

1. Add 1 hyperlink button column in DataGrid and set the text to "delete". Add the following code in aspx:


<script language="JavaScript">
  function delete_confirm(e){
    if(event.srcElement.outerText==" delete "||event.srcElement.name=="btnDictDel")
  event.returnValue=confirm(" This operation will delete permanently, ok delete? ");
  }
  document.onclick=delete_confirm;
 </script>

2. Add a hyperlink button column in DataGrid, and set ID as "del" to bind the data. The code is as follows:


for(int i=0;i< myCount;i++)
{
 ((ImageButton)dataGrid.Items[i].FindControl("del")).Attributes.Add("onclick","return confirm(' This operation will delete permanently, ok delete? ");')");
}

Related articles: