Hi Guys,
I was struggling how to display image from MSSQL image column. One solution i found was to create a handler and then in the "Src" attribute set the path to handler and passing the file name. But this didn't solved my problem as i have a shared hosting and the server doesn't allows me to add a handler.
This gave me an idea to search the solution and I found the following solution. This is also applicable to MSSQL varbinary(max) column. Below is the code which is easy to understand.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource2" Width="169px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<%--<%# System.Convert.ToBase64String((byte[])Eval("Picture"))%>--%>
<img width="100px" height="100px" src='data:image/png;base64,<%#System.Convert.ToBase64String((byte[])Eval("Picture"))%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CheckImageConnectionString %>"
SelectCommand="SELECT [ID], [Picture], [FullSnap] FROM [Emp]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:lpuumsConnectionString %>"
SelectCommand="select id,picture,fullsnap from employeepicture where id in (3,4,5)">
</asp:SqlDataSource>
Thanks
Ritesh