Display an images in Datagrid

S

sameer

Hi All,
heres an easy question which for benig new , i cannot figure it out.

A datatable pulled from the database which has 10 columns is binded to a
datagrid and it shows all of them in the datagrid successfully. Now i want to
add an image next to each record inteh grid, the image is stored on the
server( not in the dabtase) but the datatable has the path of the image
(since the path is stored in the database).

The question is how can i show this image in the datagrid right next to each
record.
Woudl be great if someone points to samples.

thanks
 
P

Phillip Williams

You can add a TemplateColumn with a Image server control defined inside its
ItemTemplate:

<asp:TemplateColumn HeaderText="Person Name">
<ItemTemplate>
<asp:Image ImageUrl =<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>
Runat=server ></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
 
S

sameer

right now i did not set any template for the columns of this grid,i jsut take
the datatable and bind it to the datagrid. So when i add this template column
, woudl i have to change any properties like define all the other columns as
well? or it shold work seemless?

thanks
 
P

Phillip Williams

Hi Sameer,

Explicitly declared template columns appear first followed by the
Auto-generated columns.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top