数据捆绑

zj558 2005-05-23 10:44:34
在做数据捆绑时,
不知道怎么样才能捆绑图片.
普通的类型捆绑为:this.txtComment.DataBindings.Add("Text",myDs,"productinfo.pro_comm");
但图片呢?
我们先要把它转化成流的格式:
byte[] byteBLOBData = (byte[])(dr["imgdata"]);
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
pic1.Image= Image.FromStream(stmBLOBData);
但怎么样捆绑啊.
...全文
223 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zj558 2005-05-25
  • 打赏
  • 举报
回复
我是在winform中啊.

mark44404 2005-05-23
  • 打赏
  • 举报
回复
是否可以使用imageButton来实现呢?
与大多数其他 Web 服务器控件不同,Image 控件不支持任何事件;例如,它对点击鼠标不作响应。您可以使用 ImageButton Web 服务器控件来创建交互图像
zj558 2005-05-23
  • 打赏
  • 举报
回复
那我的问题是这样的,
点击下一个按钮,能够显示出图片啊.
普通类型我是可以实现的了
就是这个图片不好弄.
普通类型:
this.txtComment.DataBindings.Add("Text",myDs,"productinfo.pro_comm");
但图片怎么弄啊?
难道也是:
this.txtComment.DataBindings.Add("Image",myDs,"productinfo.imgtitle")吗?
这样是错误的啊
shuaizhen 2005-05-23
  • 打赏
  • 举报
回复
up
mark44404 2005-05-23
  • 打赏
  • 举报
回复
好像没有绑定问题吧。当你把使用FromStream之后,内存里就有一个新的拷贝了
mistysunlight 2005-05-23
  • 打赏
  • 举报
回复
如果要绑定到其他控件中就需要用另外一个页面来产生图片数据,而在控件页面上引用!
如:
<img src='showImage.aspx?Id=<%# DataBinder.Eval(Container.DataItem,"Id")%>' />
在showImage.aspx中只要按Id号查找数据库中相应的数据并且按上面的方法把图片显示在showImage 中就可以了,这时候,<img .../>中的图片就可以显示出来
mistysunlight 2005-05-23
  • 打赏
  • 举报
回复
建议研究如下网页:
http://community.csdn.net/Expert/topic/3112/3112270.xml?temp=.6695215

http://www.yesky.com/20030311/1656281.shtml

http://www.duomeiti8.org/MWebProgram/Html/Article_1268.html

http://www.net118.com/article/2005319201613.htm

http://search.csdn.net/Expert/topic/1420/1420966.xml?temp=.249325

http://search.csdn.net/Expert/topic/2248/2248025.xml?temp=.3101618

http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1
///////////////////////////////////////////////////////
///取出图片
//////////////////////////////////////////////////////
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace HNANetAdmin
{
/// <summary>
/// 显示数据库中图片。
///Author: zhou_min
/// Date: 2002-10-24
/// </summary>
public class DisplayImg : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
Display();
}

private void Display()
{
string imgid =Request.QueryString["imgid"];//显示图片Id

//数据库连接
string connstr="Data Source=10.2.10.34;database=pubs;uid=sa;pwd=sa;";
string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = '"+ imgid + "'";
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();

//显示图片
if(dr.Read())
{
Response.ContentType = dr["imgtype"].ToString();
Response.BinaryWrite( (byte[]) dr["imgdata"] );
}

//关闭连接
connection.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
yz20050510 2005-05-23
  • 打赏
  • 举报
回复
我也想知道。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧