我想打电话从数据库中的图像以ASP:Repeater控件,但我得到<图像SRC" System.Byte [] QUOT;>在结果 [英] I want to call images from database in to ASP:repeater control but I am getting <image src"System.Byte[]"> in result

查看:99
本文介绍了我想打电话从数据库中的图像以ASP:Repeater控件,但我得到<图像SRC" System.Byte [] QUOT;>在结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code在aspx文件

This is my code in aspx file

cnn.Open();
    SqlDataAdapter da1 = new SqlDataAdapter("select * from carousel", cnn);
    DataTable dt1 = new DataTable();
    da1.Fill(dt1);
    Rp1.DataSource = dt1;
    Rp1.DataBind();
cnn.Close();

这是中继

<asp:Repeater id="Rp1" runat="server">
        <ItemTemplate>
        <div class="item">
            <asp:Image ID="Image1" ImageUrl='<%# Eval("image") %>' runat="server" />
        </div>
        </ItemTemplate>
        <footertemplate></footertemplate>
</asp:Repeater>

我什么都试过,但我我真的想在此方面的帮助,每次在得到结果,我是新来的ASP.Net

I tried everything but I am getting in result every time I really want some help on this, I am new to ASP.Net

推荐答案

这是因为从数据库里的值是一个字节数组重新presenting图像的实际数据。而一个 IMG 标签的的src 需要一个URL到图像。基本上有两种方式去这个...

This is because the value coming from the database is a byte array representing the actual data of the image. Whereas the src of an img tag expects a URL to an image. There are essentially two ways to go about this...


  1. 创建一个单独的页面(或ASHX处理preferably)返回的只有的对图像(没有HTML或类似的东西),并链接到页面的数据。

  2. 的Base-64连接code中的字节数组,并包括为数据URI 的src 属性。

  1. Create a separate page (or ASHX handler preferably) which returns only the data for the image (no HTML or anything like that) and link to that page.
  2. Base-64 encode the byte array and include that as a data URI in the src attribute.

有很多的教程对于第一种选择网上。 这一次是由一个快速谷歌搜索发现,还有其他人。本质上有什么处理程序会做的是接受查询字符串的标识,使用标识来从数据库中获取的图像,然后编写相应的标题和内容的响应。为的URL的src 属性随后将是处理程序。是这样的:

There are lots of tutorials for the first option online. This one was found by a quick Google search, there are others as well. Essentially what the handler would do is accept an identifier on the query string, use that identifier to get the image from the database, then write the appropriate headers and content to the response. The URL for the src attribute would then be that handler. Something like:

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

(或任何你的数据绑定数据使用作为图像的标识符。)

(Or whatever your data-bound data uses as an identifier for the image.)

这篇关于我想打电话从数据库中的图像以ASP:Repeater控件,但我得到&lt;图像SRC&QUOT; System.Byte [] QUOT;&GT;在结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆