Foreground code:
Copy Code code as follows:
<asp:gridview id= "Gridlog" runat= "Server"
autogeneratecolumns= "False" cellpadding= "4" datakeynames= "ID"
Bordercolor= "#333" borderstyle= "solid" borderwidth= "1"
Onrowdeleting= "Publicgridrowdeleting"
Gridlines= "None" width= "98%" forecolor= "#333333" >
<footerstyle backcolor= "#507CD1" forecolor= "white" font-bold= "True"/>
<Columns>
<asp:boundfield datafield= "id" headertext= "id" insertvisible= "false"
Readonly= "True"
sortexpression= "ID" >
<itemstyle horizontalalign= "Center" width= "20px"/>
</asp:BoundField>
<asp:templatefield headertext= "Delete" showheader= "False" >
<itemstyle horizontalalign= "Center" width= "40px"/>
<ItemTemplate>
<asp:linkbutton id= "LinkButton1" runat= "Server"
causesvalidation= "False" commandname= "delete" onclientclick= "return confirm (' You confirm delete
Except? '); text= "Delete" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<rowstyle backcolor= "#EFF3FB"/>
<selectedrowstyle backcolor= "#D1DDF1" font-bold= "True" forecolor= "#333333"
/>
<pagerstyle backcolor= "#2461BF" forecolor= "white" horizontalalign= "Center"
/>
<alternatingrowstyle backcolor= "White"/>
<editrowstyle backcolor= "#2461BF"/>
<EmptyDataTemplate>
The log library is temporarily empty!
</EmptyDataTemplate>
</asp:GridView>
CS Code
Copy Code code as follows:
protected void Publicgridrowdeleting (object sender, Gridviewdeleteeventargs e)
{
String Strid = Gridlog.datakeys[e.rowindex]. Value.tostring ()//strid is the ID of the line
String strSQL = "Delete from table" +
"WHERE id =" + strid;
Perform deletes
Clientscript.registerstartupscript (GetType (), "message", "<script
language= ' JavaScript ' >alert (' delete successful! '); </script> ");
Gridbind ();
}
The key is to set a good datakeynames, you can rely on string Strid = Gridlog.datakeys
[E.rowindex]. Value.tostring (); Get the ID value of the selected column and then use this ID to perform the deletion.