Gridview's link and delete click prompt are discussed

  • 2020-06-01 09:31:29
  • OfStack

For example, Gridview has two columns: cancel and delete, click the prompt 1 to execute.
 
<asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="HospitalView.aspx?id={0}" DataTextField="id" DataTextFormatString=" cancel " HeaderText=" cancel " HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="60" ItemStyle-Width="60" /> 
<asp:CommandField ShowDeleteButton="True" DeleteText=" delete " HeaderText=" delete " HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="60" ItemStyle-Width="60" /> 

If you bind the prompt in the background like this:
 
e.Row.Cells[6].Attributes.Add("onclick","return confirm (' Are you sure you want to cancel?  ')"); 
e.Row.Cells[7].Attributes.Add("onclick","return confirm (' Are you sure you want to delete this data?  ')"); 

This is to bind events to the cell of Gridview. If you don't click on the text, just click on the cell where the text is, and the prompt will pop up, which is very unfriendly.
Solutions:
 
((HyperLink)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick","return confirm (' Are you sure you want to cancel?  ')"); 
((LinkButton)e.Row.Cells[7].Controls[0]).Attributes.Add("onclick","return confirm (' Are you sure you want to delete this data?  ')"); 

Related articles: