Okay, it seems that you've used DataTable and you're getting Image URL from that.
Let me show you one example, where I have created one custom Listview, in which I'm retrieving images from the database using Handler.
.aspx :
<asp:listview id="ListView1" runat="server" datakeynames="ImgID" xmlns:asp="#unknown">
onitemediting="ListView1_ItemEditing"
onitemdeleting="ListView1_ItemDeleting"
onitemupdating="ListView1_ItemUpdating"
onitemcommand="ListView1_ItemCommand">
<itemtemplate>
<table style="width:auto">
<tr>
<td>
<asp:checkbox id="CheckBox1" runat="server" />
</td>
<td>
<asp:image id="Image1" runat="server" imageurl="<%# "ImageHandler.ashx?ImageId=" + Eval("ImgID") %>" cssclass="Image" />
</td>
<td>
<asp:label id="NameLabel" runat="server" text="<%# Eval("Name") %>" style="color:#FFF; font-family:Segoe UI Semibold;" /> <br />
<asp:label id="CreatorLabel" runat="server" text="<%# Eval("Creator") %>" style="color:#ECECEC; font-family:Segoe UI; font-size:small;" /> <br />
<asp:linkbutton id="EditBtn" runat="server" text="Edit" commandname="Edit" cssclass="Btn" />
<asp:linkbutton id="DeleteBtn" runat="server" text="Delete" commandname="Delete" cssclass="Btn" />
</td>
</tr>
</table>
</itemtemplate>
</asp:listview>
.aspx.cs :
public void BindGrid()
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM GamesList", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
ListView1.DataSource = dt;
ListView1.DataBind();
con.Close();
}
Handler :
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
SqlConnection con = new SqlConnection(@"Data Source=rohit\sqlexpress;Initial Catalog=Games;Integrated Security=True");
try
{
con.Open();
string ImageId = context.Request.QueryString["ImageId"];
SqlCommand cmd = new SqlCommand("select AlbumArt from GamesList where ImgID = " + ImageId, con);
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
byte[] photu = dr[0] as byte[];
context.Response.BinaryWrite(photu);
context.Response.End();
}
}
catch (Exception ex)
{
ex.ToString();
context.Response.Write(ex.ToString());
}
finally
{
con.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Go with this example, (in my opinion)you don't have use Session over here. Let me know If I lost you somewhere.
-KR