images in the cells of a datagrid

E

EMW

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
 
M

Mirko Geffken

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
 
E

EMW

thanks, I'll try both of them....

rg,
Eric


Mirko Geffken said:
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

EMW said:
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
 
E

EMW

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 said:
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

EMW said:
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
 
G

Guest

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

Bin Song, MCP
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top