设断点查看,id的值总为0,为什么传不过去值啊?
使用ashx需要另外配置别的文件吗?<img   src='<%# "genimage.ashx?idid="+DataBinder.Eval(Container.DataItem,"id")%> '>
public class genimage:IHttpHandler
{
public genimage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool IsReusable
{
get{return true;}
} public void ProcessRequest(HttpContext Context)
{
SqlDataReader dr;
int id=Convert.ToInt32(Context.Request["idid"]);
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnString"]);
conn.Open();
string sqlstr="select imgname from bayi_img where id="+id;
SqlCommand comm=new SqlCommand(sqlstr,conn);
dr=comm.ExecuteReader();
string path="upload/"+dr["imgname"].ToString();
Context.Response.ContentType="image/jpg";
//if(Context.Request["thumbnail"]!=null)
//{
Bitmap bmp=new Bitmap(path);
float scale=150.0f/System.Math.Max(bmp.Height,bmp.Width);
Image thumb=bmp.GetThumbnailImage((int)(bmp.Width*scale),(int)(bmp.Height*scale),null,System.IntPtr.Zero);
thumb.Save(Context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
thumb.Dispose();

解决方案 »

  1.   

    id总为零那就与这个显示缩略图的ashx文件无关了,看看不是是绑定的时候出了些漏子?
      

  2.   

    绑顶没问题的,这是运行后的原文件,里面的都有值了啊<tr>
       <td width=150 height=150 align=center>
    <a id="list__ctl0_Hyperlink1" href="ShowUploadimg.aspx?id=5" target="blank">
    <img   src='genimage.ashx?idid=5 '>
    </a>
    </td>
    </tr>
    <tr>
       <td>
    <span id="list__ctl0_Label1">日</span>
       </td>
    </tr>
    </table>
    </td><td align="Center">
    <table>
    <tr>
       <td width=150 height=150 align=center>
    <a id="list__ctl1_Hyperlink1" href="ShowUploadimg.aspx?id=4" target="blank">
    <img   src='genimage.ashx?idid=4 '>
    </a>
    </td>
    </tr>