0

**Work on vs05 C# asp.net .**My SQL Syntax is :****

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Images]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Images]
GO

CREATE TABLE [dbo].[Images] (
    [ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
    [ImageName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Image] [image] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

I want to show this Images table values in a grid view.....I do it ...but the image value can not show ....asp.net syntax for gridview is

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="ImageName" HeaderText="ImageName" />
                <asp:TemplateField HeaderText="Image">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Image") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Image") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

i write the below code on pageload event. i want images table values must shown when the page is load...

string strSQL = "Select  *  From Images";
    DataTable dt = clsDB.getDataTable(strSQL);
    this.GridView2.DataSource = dt;
    this.GridView2.DataBind();

Why not i get the image on my image column of the gridview.....what's the problem is how to solve?

Jakob Gade
  • 12,319
  • 15
  • 70
  • 118

2 Answers2

0

Use Handlers to display images in Gridview. This is the easy and commonly used method to display image from database.

Check this link

Community
  • 1
  • 1
Vijaychandar
  • 716
  • 5
  • 21
0

You can't use the <%# Eval("Image") %> syntax inside your ASP.NET server controls. I recommend you use a plain <img> instead. Like this: <img src='<%# Eval("Image") %>' />.

Check out this this article from 4 Guys From Rolla, it deals with working with images stored as blobs in a SQL Server database. Especially the section "Displaying the Binary Content" is particularly relevant to your case. Or this very similar SO question, What’s the best way to display an image from a sql server database in asp.net?

Community
  • 1
  • 1
Jakob Gade
  • 12,319
  • 15
  • 70
  • 118