我怎样才能完成这个功能
我现在正在做一些在网格视图中显示图像组的 ASP.NET 页面,但该图像必须是指向另一个显示图像及其详细信息的页面的链接 这是我用来从数据库获取图像的函数:
<script language="C#" runat="server">
public void getImages ( Object src, GridViewRowEventArgs e ) {
if ( e.Row.RowType == DataControlRowType.DataRow )
{
DataRowView rowView = ( DataRowView ) e.Row.DataItem;
string imageid = rowView [ "imgid" ].ToString ( );
string imgstring=rowView ["image"].ToString();
byte[] img = Encoding.ASCII.GetBytes(imgstring);
TableCellCollection myCells = e.Row.Cells;
}
}
</script>
通过此代码,我从数据库获取图像,但作为字节数组 我无法将字节转换为其原始图像,
这是显示图像的网格视图
它的值是:
<asp:hyperlinkfield
datanavigateurlfields="image"
datanavigateurlformatstring="Default2.aspx?id={0}" >
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
<asp:hyperlinkfield
datanavigateurlfields="imgid"
datanavigateurlformatstring="Default2.aspx?id={0}">
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
<asp:hyperlinkfield
datanavigateurlfields="imgid"
datanavigateurlformatstring="Default2.aspx?id={0}">
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
</columns>
这是sql数据源
“ SelectCommand="SELECT [imgid],[image] FROM [Image]"> 现在,当运行代码时,会显示网格视图,
我必须更改或添加什么才能使图像显示在网格视图中,当单击其中的任何图像时,会转到另一个页面,其中包含图像及其详细信息
iam now doning some asp.net page that display group of images in grid view but this image must be a link to another page displaying the image and its details
this is the function i use to get images from data base:
<script language="C#" runat="server">
public void getImages ( Object src, GridViewRowEventArgs e ) {
if ( e.Row.RowType == DataControlRowType.DataRow )
{
DataRowView rowView = ( DataRowView ) e.Row.DataItem;
string imageid = rowView [ "imgid" ].ToString ( );
string imgstring=rowView ["image"].ToString();
byte[] img = Encoding.ASCII.GetBytes(imgstring);
TableCellCollection myCells = e.Row.Cells;
}
}
</script>
by this code i get the image from the database but as array of bytes
i couldn't convert the bytes to its original images
this is the grid view that display images
and its coulmns are :
<asp:hyperlinkfield
datanavigateurlfields="image"
datanavigateurlformatstring="Default2.aspx?id={0}" >
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
<asp:hyperlinkfield
datanavigateurlfields="imgid"
datanavigateurlformatstring="Default2.aspx?id={0}">
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
<asp:hyperlinkfield
datanavigateurlfields="imgid"
datanavigateurlformatstring="Default2.aspx?id={0}">
<controlstyle borderwidth="1" borderstyle="inset" />
</asp:hyperlinkfield>
</columns>
and this is the sql data source
"
SelectCommand="SELECT [imgid],[image] FROM [Image]">
now when running the code a grid view is shown embty
what i must change or add to make the images to display in the grid view and when clicking on any image in it go to another page has the image and it's details
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将图像存储在数据库中时,将它们显示在 gridview 或网页上的任何其他位置中的最佳方法是使用 HTTP 处理程序。
查看此链接
When you have images stored in database, best way to get them for displaying in the gridview, or any other place on the web page is to use HTTP Handlers.
Check this link out