2014年7月13日 星期日

[RESOLVED] ImageHandling error


Hi,


I have some problems loading my image file into the gridview control.


Please see screenshot: http://imageshack.us/photo/my-images/708/92zh.jpg/


Image handling ashx file:


public void ProcessRequest(HttpContext context)

{

objCmd.CommandText = "Select ImgSrc from M_DMemPict" + " where ImageId=@ImageId";

objCmd.CommandType = System.Data.CommandType.Text;

objCmd.Connection = objConn;

SqlParameter ImageID = new SqlParameter("@ImageId", System.Data.SqlDbType.Int);

ImageID.Value = context.Request.QueryString["img"];

objCmd.Parameters.Add(ImageID);

objConn.Open();

SqlDataReader dReader = objCmd.ExecuteReader();

dReader.Read();

context.Response.BinaryWrite((byte[])dReader["ImgSrc"]);

dReader.Close();

objConn.Close();


context.Response.ContentType = "image/jpeg";

context.Response.AppendHeader("Content-Disposition", "attachment; filename=test.JPG");

//context.Response.TransmitFile(@"D:\\test.jpg");

//context.Response.End();


}


Please help, thanks.



Check your query first at the Database , did it returns the column "ImageId" or not.



this is the case of since your query doest not returns the column ImageId



@Rjk_P,


my query is correct however could you please correct this syntax from the gridview control using templatefield tag.



ImageUrl='<%# "~/ImgHandler.ashx?id=" + Eval("ImageId")%>'/>


The image is not displaying on the gridview. 


Thanks.



Your are passing id as parmenter and taking img as  request context querysting value at server side. Change it and try..



Hi,


The error is DataBinding:System.Data.DataRowView" does not contain a property with the name 'ImageId'.


So please try to check if you have a column named 'ImageId', Or you have mistake the name of the column.


Hope it can help you.


Best Regards,

Amy Peng 


沒有留言:

張貼留言