J
Jeff
hey
asp.net 2.0
visual web developer 2005 express
I have a webpage which contains 1 Repeater control. Into this repeater
control I want to add several rows of data. My problem is that 1 of the data
is an array of bytes (it's a picture saved to the database as bytes) and I
want that picture to be displayed nicely in the repeater list....
Here is two approaches (approach A and approach B) I'm trying:
APPROACH A:
Use the scenario of 2 .aspx files, 1 .aspx (A) convert the bytes of array
into a picture and the other .aspx file (B) has a img tag pointing to the
first .aspx file (A)
But here I get problems with this line "img.Src =
"Thumnail.aspx?ImageID=1";", it looks like it expects a object... Somehow I
need to send over a parameter to this Thumbnail.aspx file about which image
to display... Lets say the resultset has many images, but this row shall
display one particular image
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
System.Web.UI.HtmlControls.HtmlImage img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.HtmlControls.HtmlImage)e.Item.FindControl("Photo");
img.Src = "Thumnail.aspx?ImageID=1";
}
}
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="inbox.aspx.cs"
Inherits="webForms_Profile_inbox" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<asp:ObjectDataSource ID="odsInbox" runat="server"
SelectMethod="getInbox" TypeName="BusinessLogic.NetworkLogic">
</asp:ObjectDataSource>
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<img ID="Photo" src="" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="sidebar" Runat="Server">
</asp:Content>
****************************************************************
APPROACH B:
In this approach I tryed to replace the img tag with a Image control in the
repeater.
But the "System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);"
gives this error:
"Parameter is not valid."
Another thing is that I'm not sure this is a good approach because it uses
bmp.Save() and I'm afraid the server will run out of space if images get
saved on the server each time th page is displayed???
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
//System.Web.UI.HtmlControls.HtmlImage img = null;
System.Web.UI.WebControls.Image img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.WebControls.Image)e.Item.FindControl("Photo");
byte[] data = Profile.Picture;
Int32 offset = 78;
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, offset, data.Length - offset);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath("sample.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();
img.ImageUrl = Server.MapPath("sample.jpeg");
}
//e.Item.DataItem.ToString();
}
Please help me with this one, I'm stucked in this problem....
Best Regards
Jeff
asp.net 2.0
visual web developer 2005 express
I have a webpage which contains 1 Repeater control. Into this repeater
control I want to add several rows of data. My problem is that 1 of the data
is an array of bytes (it's a picture saved to the database as bytes) and I
want that picture to be displayed nicely in the repeater list....
Here is two approaches (approach A and approach B) I'm trying:
APPROACH A:
Use the scenario of 2 .aspx files, 1 .aspx (A) convert the bytes of array
into a picture and the other .aspx file (B) has a img tag pointing to the
first .aspx file (A)
But here I get problems with this line "img.Src =
"Thumnail.aspx?ImageID=1";", it looks like it expects a object... Somehow I
need to send over a parameter to this Thumbnail.aspx file about which image
to display... Lets say the resultset has many images, but this row shall
display one particular image
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
System.Web.UI.HtmlControls.HtmlImage img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.HtmlControls.HtmlImage)e.Item.FindControl("Photo");
img.Src = "Thumnail.aspx?ImageID=1";
}
}
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="inbox.aspx.cs"
Inherits="webForms_Profile_inbox" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<asp:ObjectDataSource ID="odsInbox" runat="server"
SelectMethod="getInbox" TypeName="BusinessLogic.NetworkLogic">
</asp:ObjectDataSource>
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<img ID="Photo" src="" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="sidebar" Runat="Server">
</asp:Content>
****************************************************************
APPROACH B:
In this approach I tryed to replace the img tag with a Image control in the
repeater.
But the "System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);"
gives this error:
"Parameter is not valid."
Another thing is that I'm not sure this is a good approach because it uses
bmp.Save() and I'm afraid the server will run out of space if images get
saved on the server each time th page is displayed???
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
//System.Web.UI.HtmlControls.HtmlImage img = null;
System.Web.UI.WebControls.Image img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.WebControls.Image)e.Item.FindControl("Photo");
byte[] data = Profile.Picture;
Int32 offset = 78;
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, offset, data.Length - offset);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath("sample.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();
img.ImageUrl = Server.MapPath("sample.jpeg");
}
//e.Item.DataItem.ToString();
}
Please help me with this one, I'm stucked in this problem....
Best Regards
Jeff