Hello all of you,
i m trying to get image from database to asp:repeater
for that i am using one handler page but not able to get the image
here is the code for asp:repeter
<asp:Repeater ID="rep"
runat="server" >
<HeaderTemplate>
<table>
<tr>
<th>
Image</th>
<th>
Basic Information</th>
</HeaderTemplate>
<ItemTemplate>
<tr >
<td align="center">
<asp:Image ID="img" runat="server" ImageUrl='~/ShowImage.ashx?pro_id="<%# Eval("pro_id")%>"' />
</td>
<asp:Label ID="Label4" runat="server" Text="Type" Font-Bold="True"></asp:Label>
<asp:Label ID="Label1"
Text='<%# Eval("pro_type") %>'
runat="server" />
<asp:LinkButton ID="lnk" runat="server" Text="More"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ShowImage code is here !
public class ShowImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
string pro_id;
if (context.Request.QueryString["pro_id"].ToString() != null)
{
pro_id = (context.Request.QueryString["user_id"].ToString());
}
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowEmpImage(pro_id);
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);
}
context.Response.BinaryWrite(buffer);
}
catch (Exception ex)
{
}
}
public Stream ShowEmpImage(string pro_id)
{
sql ob = new sql();
ob.conection.Open();
ob.sq = new SqlCommand("select image1 from tbl_product where pro_id=@pro_id", ob.conection);
obj.sql1.Parameters.Add("@pro_id", SqlDbType.VarChar).Value = pro_id.Trim();
object img = obj.sql1.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
obj.conection.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
but still not able to get image on repeter ! :(