Delete server images and server Images
Delete server Images
Example of how to bind GridView1 to a database and delete an image:
Cs file:
BIND database:
private string connStr = ConfigurationManager.ConnectionStrings["qiyesql"].ConnectionString;
Delete server images:
Protected void GridView1_RowDeleting1 (object sender, GridViewDeleteEventArgs e) {SqlConnection con = new SqlConnection (connStr); con. open (); SqlCommand com = new SqlCommand ("select image from huandengyi where id = '" + GridView1.DataKeys [e. rowIndex]. value. toString () + "'", con); SqlDataReader dr = com. executeReader (); if (dr. read () {string path = HttpContext. current. server. mapPath ("~ /"+ Dr [" image "]. toString (); if (File. exists (path) {File. delete (path);} else {Response. write ("<script> alert ('image does not exist or deleted '); </script>") ;}} else {Response. write ("<script> alert ('data error'); </script> ");}}
Add attributes to aspx GridView1
OnRowDeleting="GridView1_RowDeleting1"