I have an image control on the aspx page like this
<asp:Image ID="Image1" runat="server" Height="64px" Width="64px"
ImageUrl='<%# "SideImageHandler.ashx?ID=" + Eval("ID")%>'/>
And my imagehandler code looks like this
public void ProcessRequest(HttpContext context)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["GalleryConnectionString"].ConnectionString;
// Create SQL Command
Utility.ImageID = 2;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT IMAGE FROM Icon WHERE (ID ="+ Utility.ImageID+")";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int);
ImageID.Value = context.Request.QueryString["ID"];
cmd.Parameters.Add(ImageID);
con.Open();
SqlDataReader dReader = cmd.ExecuteReader();
dReader.Read();
context.Response.BinaryWrite((byte[])dReader["IMAGE"]);
dReader.Close();
con.Close();
}
But it is not showing me the image. whats going wrong with it?
Also, I have a download button when the user clicks on it the image will be downloaded I'm newer don't know what the code I put on the download button click event? Kindly guide me thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…