Hi ramkiran,
Refer theb below sample.
HTML
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#3366CC"
BorderStyle="None" BorderWidth="1px" CellPadding="0" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="UserId">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image ID="Image3" runat="server" ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>'
Width="125px" Height="55px"></asp:Image>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Designation">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("designation") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM tblFiles WHERE ContentType = 'image/jpeg'";
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ConnectionString)
Using cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM tblFiles WHERE ContentType = 'image/jpeg'"
con.Open()
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Dim dt As New DataTable()
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
con.Close()
End Using
End Using
End If
End Sub
Screenshot
