views:

762

answers:

2

I have a pictures table that has the following columns:

PICTURE_ID int IDENTITY(1000,1) NOT NULL,
CATEGORY_ID int NOT NULL,
IMGDATA image NOT NULL,
CAPTION1 text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
MIME_TYPE nchar(20) NOT NULL DEFAULT ('image/jpeg'),
IMGTHDATA image NOT NULL

In my code-behind I have this:

string tableName = "CATPICS";
SqlConnection dbConnection = new SqlConnection(connStr);
SqlDataAdapter daCatPics = new SqlDataAdapter("SELECT TOP(3) * FROM CATEGORY_PICTURES", dbConnection);
DataSet dsPics = new DataSet();
daCatPics.Fill(dsPics, tableName);

gvCatPics.DataSource = dsPics;
gvCatPics.DataMember = tableName;
gvCatPics.DataBind();

On the markup I pretty much have:

<asp:GridView ID="gvCatPics" runat="server"></asp:GridView>

However when the code executes, it simply ignores the two image columns (IMGDATA and IMGTHDATA). For some reason it doesn't recognize that they are image columns. Does anyone know of the simplest way of having it render the image?

+1  A: 

There is no real simple way to do this. Basically you're going to need to create a handler to display the images. Then in your grid you will create an img tag with the URL pointing to your image handler.

An example of this can be found here.

Update: Much better example of this here.

Bryant
+3  A: 

you can make a page that returns the image as a stream and reference that page from an Image column (or an IMG tag in a template column); see GridViewDisplayBlob.aspx

Steven A. Lowe