unfortunately I can not display my image using repater and generic handler which I called ImageHandler.ashx, probably I am doing something wrong, and I can not spot mistake by myself.
Here is my code (btw this is first time I am using this generic handler in combination with repeater to get my images from databases and I am stucked here).
Here is my code:
<table class="table table-hover" style="margin-top: 50px; background-color: white;">
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Photo</th>
</tr>
<asp:Repeater ID="repPlayers" runat="server" OnItemCommand="repPlayers_ItemCommand">
<ItemTemplate>
<tr>
<td><%# Eval("Name") %></td>
<td><%# Eval("LastName") %></td>
<td>
<asp:Image ID="imageTest" src="~/ImageHandler.ashx?id=PlayerID" runat="server" />
<%--<img id="imageTest" style="width: 60px; height: 30px;" src="data:image/png;base64, <%# Convert.ToBase64String((byte[])Eval("Photo")) %> " />--%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
ImageHandler.ashx CODE BEHIND:
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
int playerID = Convert.ToInt32(context.Request["PlayerID"]);
Players.Data.DataAccess player = Players.Data.DataAccess.GetByPlayerId(playerID);
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(player.Photo);
}
public bool IsReusable
{
get
{
return false;
}
}
}
Probably I am doing something wrong, maybe I should combine '<%#Eval("PlayerID")%>'
somehow or whatever?
If I were using datagrid I would use Item_dataBound control and that could solve myproblem but unfortunately I am loading my data here into table and I don't know how to solve this..
edit:
I tried this too and that was solution:
<asp:Image ID="imageTest" runat="server"
ImageUrl='<%#"~/ImageHandler.ashx?PlayerID="+Eval("PlayerID") %>' />
P.S Commented code works but its is loading images slow as hell and that makes my whole page loads very slow because I am getting like 50 objects from database and each of them has image :(
BECAUSE I POST ABOVE WHAT WAS SOLUTION, WE CAN THREAT THIS AS CLOSED!