Groups | Blog | Home
all groups > asp.net > may 2004 >

asp.net : images in the cells of a datagrid


Mirko Geffken
5/19/2004 6:58:51 PM
I am replying to this by memory:

You have two options

1) In the OnItemDataBound event simply grab a reference to the cell
(somthing like e.item.Cells[2] and add an image to the control collection
Image img=new Image();
img.ImageUrl="/images/" +
DataBinder.Eval(e.Item.DataItem,"MyImageColumnName");
e.item.Cells[2].Controls.Add(img);

2) Simply add a templated column and set the ImageUrl property of an
<asp:image tag to something like
<%#DataBinder.Eval(Container.DataItem,"MyImageColumnName")%>

Hope this helps

Mirko

[quoted text, click to view]

EMW
5/19/2004 11:56:16 PM
For my ASP.NET program I want to use the datagrid as a sort of planning
tool.
Based on the information in a XML file, a cell of the datagrid must show an
image...

Well, this is what I would like it to do, but is it possible and how can I
place an image in
a web-datagrid cell?

rg,
Eric

Bin Song, MCP
5/20/2004 6:41:03 AM
Hi

If you just want to fill a specific cell in a specific row
Add you code into a If block
If e.Item.Index = myRow The
.....
End I
If you just want to fill a specific cell on a condition of other column value
If e.Item.DataItem("CertainColumn") = CertainValue The
......
End I

EMW
5/20/2004 12:54:10 PM
thanks, I'll try both of them....

rg,
Eric


"Mirko Geffken" <mirkogeffken@oddpost.com> schreef in bericht
news:O5xXlTfPEHA.3348@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

EMW
5/20/2004 1:26:03 PM
Hi,

I have used the following code, but instead of just one cell , all cells of
the column are filled with the image.

Private Sub dgMaand_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgMaand.ItemDataBound
Dim FilePath As String
FilePath = Request.PhysicalApplicationPath
Dim columnnaam As String = "01"
Dim img As New Image
img.ImageUrl = FilePath + "\blok_groen.jpg"
DataBinder.Eval(e.Item.DataItem, columnnaam)
e.Item.Cells(5).RowSpan = 1
e.Item.Cells(5).ToolTip = "test"
e.Item.Cells(5).Controls.Add(img)
End Sub

So, how can I just fill one cell with the image?

rg,
Eric





"Mirko Geffken" <mirkogeffken@oddpost.com> schreef in bericht
news:O5xXlTfPEHA.3348@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button