Refrence image in datagrid with OnItemDataBound

  • Thread starter David A. Coursey
  • Start date
D

David A. Coursey

I am trying to change the image in my column depending on the status of the
db field. All of the data is being populated correctly, I just haven't been
able to get the image path to work.

aspx page:

<asp:boundcolumn visible="False" datafield="success" />
<asp:templatecolumn headertext="Status" >
<itemtemplate>
<asp:image id="imgWebStatus" runat="server" imageurl="" />
</itemtemplate>
</asp:templatecolumn>



aspx.cs codebehind page:


if(e.Item.ItemType.Equals(System.Web.UI.WebControls.ListItemType.Item) ||
e.Item.ItemType.Equals(System.Web.UI.WebControls.ListItemType.AlternatingItem))
{
switch(Convert.ToInt32(e.Item.Cells[0].Text))
{
case 0:
{
e.Item.Cells[1].WHAT_GOES_HERE = Request.ApplicationPath +
"/images/no.gif";
break;
}



Thanks for looking.

David A. Coursey
 
E

Eric Cherng

You want to get a reference to your Image control. Something like...

Image img = (Image) e.Item.FindControl("imgWebStatus");
img.ImageUrl = ... your picture url here ...;
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top