using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq; using System.Data.SqlClient; using System.IO; namespace EDS { public partial class WebForm4 : System.Web.UI.Page { String strcon = ConfigurationManager.ConnectionStrings["con"].ToString(); SqlConnection Scon; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridviewData(); } } private void BindGridviewData() { Scon = new SqlConnection(strcon); Scon.Open(); SqlCommand cmd = new SqlCommand("select * from SaveData",Scon); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); Scon.Close(); gvDetails.DataSource = ds; gvDetails.DataBind(); } protected void lnkDownload_Click(object sender, EventArgs e) { LinkButton lnkbtn = sender as LinkButton; GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow; string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString(); Response.ContentType = "image/jpg"; Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\""); Response.TransmitFile(Server.MapPath(filePath)); Response.End(); } protected void lnkdelete_Click(object sender, EventArgs e) { LinkButton lnkbtn = sender as LinkButton; //getting particular row linkbutton GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow; //getting userid of particular row string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString(); //string username = gvrow.Cells[0].Text; Scon.Open(); SqlCommand cmd = new SqlCommand("delete from SaveData where FilePath=" + filePath, Scon); int result = cmd.ExecuteNonQuery(); Scon.Close(); if (result == 1) { BindGridviewData(); //Displaying alert message after successfully deletion of user ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + filePath + " details deleted successfully')", true); }
as
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)