Refrence image in datagrid with OnItemDataBound

Discussion in 'ASP .Net Web Controls' started by David A. Coursey, Oct 5, 2004.

  1. 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
     
    David A. Coursey, Oct 5, 2004
    #1
    1. Advertising

  2. David A. Coursey

    Eric Cherng Guest

    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 ...;

    --
    Eric Cherng
    MCP, MCDBA, MCSD
    http://echerng.com


    "David A. Coursey" <> wrote in message
    news:%...
    >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
    >
    >
    >
    >
     
    Eric Cherng, Oct 6, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike John
    Replies:
    1
    Views:
    511
    Axel Dahmen
    Jun 29, 2003
  2. Steven
    Replies:
    1
    Views:
    1,666
    Simon
    Jul 9, 2003
  3. xzzy
    Replies:
    3
    Views:
    515
    Teemu Keiski
    Jun 18, 2006
  4. ITnerd
    Replies:
    1
    Views:
    152
    Giorgio Parmeggiani
    Nov 2, 2003
  5. David A. Coursey

    Refrence image in template column

    David A. Coursey, Oct 4, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    110
    Michael Tkachev
    Oct 6, 2004
Loading...

Share This Page