Solution: a prompt will be displayed during the delete operation, asking the user if they want to delete the file. The most commonly used is the confirm function of Js.
The advantage of using this function is that the reality is simple, and the disadvantage is: not beautiful
This is an article written to beautify confirm.
JS special effects code used for: http://download.csdn.net/detail/wangsky2/3909680
General idea: Create a server control button and a tag in the gridview delete operation template.
ASP: the button is set to invisible. The a mark is used to execute the JS script, and the background of the button is called to execute the operation in the execution of the JS script.
The Code is as follows:
<Asp: updatepanel id = "updatepanel2" runat = "server" childrenastriggers = "true">
<Contenttemplate>
<Asp: gridview id = "gvlist" runat = "server" autogeneratecolumns = "false" width = "100%"
Cssclass = "Table break" allowpaging = "true" ondatabound = "gvlist_databound"
Onrowdatabound = "gvlist_rowdatabound"
Onrowcommand = "delchilduserordevice"
Datakeynames = "ID, devid" onrowcancelingedit = "gvlist_rowcancelingedit"
Onrowediting = "gvlist_rowediting"
Onrowupdating = "gvlist_rowupdating" showheaderwhenempty = "true" gridlines = "NONE"
Cellpadding = "4" forecolor = "#333333">
<Columns>
Other data binding operations ......
<Asp: templatefield headertext = "operation">
<Itemtemplate>
<Asp: button id = "btndeldevice" commandname = "deldevice" runat = "server" text = "button" commandargument = "<% # container. dataitemindex %> "style =" display: none "/>
<A href = "javascript: deldevicerow (<% # container. dataitemindex %>);"> Delete </a>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>
</Contenttemplate>
</ASP: updatepanel>
I used updatepanel to perform simple asynchronous refresh during deletion.
JS Code:
/// // Start ////////////////////////////////////
VaR devicedelrowindex; // Delete the index of the current row of the device.
// Delete the callback function of the device.
Function devicedelrowcallback (TP ){
If (TP = 'OK '){
VaR gridview = Document. getelementbyid ("<% = gvlist. clientid %> ");
Gridview. Rows [devicedelrowindex]. cells [4]. getelementsbytagname ("input") [0]. Click ();
}
}
// Delete a device's Function
Function deldevicerow (rowindex ){
Ymprompt. confirminfo ('Are you sure you want to delete this row? ', Null, null, 'message', devicedelrowcallback );
Devicedelrowindex = rowindex + 1;
}
/// // End/ ///////////////////////
Background deletion operation code:
Protected void delchilduserordevice (Object sender, gridviewcommandeventargs E)
{
Code ........
}
If you have a senior, please kindly advise ^_^