在中继器控件上显示图像
使用 C# ASP.NET。我在中继器控制方面遇到问题。我想在存储在数据库中的页面上显示图像。我从 Northwind 数据库收集信息。
类别表
SQL语法:
CREATE TABLE [dbo].[Categories](
[CategoryID] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [nvarchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Description] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Picture] [image] NULL)
页面加载时C#语法:
NorthWindDataContext db = new NorthWindDataContext();
List<Category> oList = new List<Category>();
oList = db.Categories.ToList();
Repeater1.DataSource = oList;
aspx语法:
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container, "DataItem.Picture")%>
</td>
</tr>
</ItemTemplate>
运行代码后,在我的页面中没有得到图片。帮助我在我的页面上获取图片。提前致谢。如果有任何疑问,请询问。
Work on C# ASP.NET. I have a problem with repeater control. I want to show images on a page that is stored in a database. I collect information from northwind database.
Categories table
SQL syntax:
CREATE TABLE [dbo].[Categories](
[CategoryID] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [nvarchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Description] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Picture] [image] NULL)
On pageload C# syntax :
NorthWindDataContext db = new NorthWindDataContext();
List<Category> oList = new List<Category>();
oList = db.Categories.ToList();
Repeater1.DataSource = oList;
aspx Syntax:
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container, "DataItem.Picture")%>
</td>
</tr>
</ItemTemplate>
After run the code,in my page i don't get the picture.help me to get picture on my page .Thanks in advance .If have any query plz ask.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将图像作为二进制数据存储在数据库中,因此无法按原样显示它。
MSDN 关于
image
数据类型:常见的方法是从内存流创建 System.Drawing.Image 的实例,然后将其显式写入响应中。此功能应由 ASHX 处理程序包装。参见intrawebs 的例子,有很多。
下面的处理程序伪代码:(然后在 ASPX 中只是引用处理程序)
我发现的好例子:
You are store images as binary data in a data base so you can not show it as is.
MSDN on
image
data type:The common approach is to create instance of the
System.Drawing.Image
from a memory stream and then write it explicitly inr response. This functionality should be wrapped by ASHX handler. See intrawebs for the examples, there are a lot.Handler pseudo code below: (then in ASPX just reffer handler)
Good examples I've found: