我有个datagrid,每行里有个<image>,如下:
<ItemTemplate>
<asp:image id="imgPic" runat="server" ImageUrl='<%# FormatImage(DataBinder.Eval(Container.DataItem, "PicID")) %>'></asp:image>
</ItemTemplate>cs文件中有:
protected string FormatImage(object obj)
{
return "showPic.aspx?picid=" + obj.ToString();
}
==============================
showPic.aspx页面如下:
private void Page_Load(object sender, System.EventArgs e)
{
int picid = Request["picid"]==null?-1:Convert.ToInt32(Request["picid"]); if(picid <= -1)
{
Response.Write("没有图片");
}
else
{
DbTool tool = new DbTool ();//连接数据库 string sql = "select picture,pic_type,pic_size from ba_crm_pic where pic_id=" + picid;
SqlDataReader reader = tool.RunRdSql(sql); reader.Read();
Response.ContentType = (string)reader["pic_type"];//设定输出文件类型
//输出图象文件二进制数制
Response.BinaryWrite((byte[])reader["picture"]);
Response.End();
reader.Close();
}
}
=============================
为什么我打开datagrid的页面,图片位置不显示图片
如果单独打开showPic.aspx?picid=1,则会出现“文件下载”的窗口,为什么呢?哪位高手能帮我看看?谢了啊
<ItemTemplate>
<asp:image id="imgPic" runat="server" ImageUrl='<%# FormatImage(DataBinder.Eval(Container.DataItem, "PicID")) %>'></asp:image>
</ItemTemplate>cs文件中有:
protected string FormatImage(object obj)
{
return "showPic.aspx?picid=" + obj.ToString();
}
==============================
showPic.aspx页面如下:
private void Page_Load(object sender, System.EventArgs e)
{
int picid = Request["picid"]==null?-1:Convert.ToInt32(Request["picid"]); if(picid <= -1)
{
Response.Write("没有图片");
}
else
{
DbTool tool = new DbTool ();//连接数据库 string sql = "select picture,pic_type,pic_size from ba_crm_pic where pic_id=" + picid;
SqlDataReader reader = tool.RunRdSql(sql); reader.Read();
Response.ContentType = (string)reader["pic_type"];//设定输出文件类型
//输出图象文件二进制数制
Response.BinaryWrite((byte[])reader["picture"]);
Response.End();
reader.Close();
}
}
=============================
为什么我打开datagrid的页面,图片位置不显示图片
如果单独打开showPic.aspx?picid=1,则会出现“文件下载”的窗口,为什么呢?哪位高手能帮我看看?谢了啊
解决方案 »
- |zyciis| 如何用一个方法,调用某个对像的click事件,并改变他的参数,谢谢
- datalist换行问题
- 防止数据记录被篡改
- 循环判断一组数据 不符条件就弹出对话框修改内容 关闭之后继续循环
- 我触发datagrid里自定义列中的ddl的selectedchange方法,如何在这个方法中能捕捉datagrid中的值呢?
- 我想学asp.net,但是我是一点编成经验都没有,完全一个初学者,各位高手请给我一个方向
- (给分)请各位对我们的产品页面给意见
- 如何用JavaScript取得图片的长和宽??
- 按钮问题,高手请进,在线等待
- 一个比较奇怪但不解决不行的问题————200分送上!
- dataGrid中添加滚动条!
- XML文件怎么以网页形式出来呢?像http://community.csdn.net/Expert/topic/4636/4636064.xml?temp=.8466761这个样子?
你最好先生成一个图片文件 比如a.JPG
然后在把数据库得图片写到a.JPG里面去
再调用a.JPG
---------------------------
苦海无边 回头无岸
---------------------------
在showimg.aspx中写
this.Conn.Open();
string sql="select * from newspic where id='"+imageid+"'";
da=new SqlDataAdapter(sql,Conn);
ds=new DataSet();
da.Fill(ds,"newspic");
if(ds.Tables[0].Rows.Count<=0)
{
Response.Write("");
Response.End();
return;
}
else
{
Session["pic"]=ds.Tables[0].Rows[0]["pic"];
Session["pictype"]=ds.Tables[0].Rows[0]["pictype"];
Response.Expires=0;
Response.Buffer=true;
Response.Clear();
Response.ContentType=Session["pictype"].ToString();
Response.BinaryWrite((byte[])Session["pic"]);
Session["pic"]="";
Session["pictype"]="";
}
然后你在别的页面可以这样用
<img src="showimg.aspx?id=<%=id%>">