我有一个名为PIMAGE的字段的表,而我无法显示此字段。 GridView控件命名为:dgw- 我的问题是,在GridView不显示图像 我的代码:如何在GridView表单数据库中显示图像linq
protected void Page_Load(object sender, EventArgs e)
{
StorDataContext stor = new StorDataContext();
var res = (from r in stor.Products
where r.PID!=13
select new {
name=r.PName,date=System.DateTime.Now.ToString(),company=r.Company,price=r.Price,quantity=r.Quantity,color=r.Color,size=r.Size,weight=r.PWeight,
PImage = r.PID});
GridView1.Visible = true;
GridView1.DataSource = res.ToList();
GridView1.DataBind();
}
,并可能ASHX
public class ShowImg : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
Int32 pid;
if (context.Request.QueryString["getID"] != null)
{
pid = Convert.ToInt32(context.Request.QueryString["getID"]);
context.Response.ContentType = "image/jpeg";
Stream strm = GetImage(pid);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
}
public Stream GetImage(int pid)
{
StorDataContext stor = new StorDataContext();
System.Data.Linq.Binary b = null;
byte[] ibyte = null;
Product product1 = stor.Products.First(p => p.PID == pid);
b = product1.PImage;
ibyte = b.ToArray();
return new MemoryStream((byte[])ibyte);
}
和ASPX
<asp:TemplateField HeaderText="PImage">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/ShowImg.ashx?id=" + Eval("PImage") %>' />
</ItemTemplate>
</asp:TemplateField>
什么是错的? 使用asp.net-sql server -linq
更多信息可以帮助您在这里的Page_Load 。你的Person类是什么样的?什么是你绑定的领域?你的GridView代码是什么样的? –