I have used the download button in the gridview
Use this handler
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Net;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
SqlConnection con = con_manager.getcon();
string sql = "SELECT column_name FROM table " +
"WHERE condition";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@ScanID", SqlDbType.VarChar).Value = context.Request.QueryString["id"];
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()) //yup we found our image
{
context.Response.ContentType = dr["content_type"].ToString();
string filename = dr["file_name"].ToString();
context.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
context.Response.BinaryWrite((byte[])dr["imagedata"]);
}
con.Close();
}
public bool IsReusable {
get {
return false;
}
}
}
and call that handler in the gridviewselected index changed event by passing the id
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string rowid;
rowid = GridView1.SelectedDataKey[0].ToString();
Response.Redirect("Download_Handler.ashx?id=" + rowid);
}
Pavanpp, if this helps please login to Mark As Answer. | Alert Moderator