By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

images in the cells of a datagrid

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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,"MyImageColu mnName")%>

Hope this helps

Mirko

"EMW" <SomeOne@MicroSoftdotCom> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
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

Nov 18 '05 #2

P: n/a
EMW
thanks, I'll try both of them....

rg,
Eric
"Mirko Geffken" <mi**********@oddpost.com> schreef in bericht
news:O5**************@TK2MSFTNGP09.phx.gbl...
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,"MyImageColu mnName")%>

Hope this helps

Mirko

"EMW" <SomeOne@MicroSoftdotCom> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
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


Nov 18 '05 #3

P: n/a
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" <mi**********@oddpost.com> schreef in bericht
news:O5**************@TK2MSFTNGP09.phx.gbl...
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,"MyImageColu mnName")%>

Hope this helps

Mirko

"EMW" <SomeOne@MicroSoftdotCom> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
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


Nov 18 '05 #4

P: n/a
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
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.