How to display an icon in the gridview cell column dependent on another column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yahshuatwo
    New Member
    • May 2010
    • 1

    How to display an icon in the gridview cell column dependent on another column

    How can you display an icon the gridview cell column which is dependent on the text value of an adjacent column. Also, I setup the asp template,item and image controls, do i need to set the imgURL value in the asp control side? here's my code below:

    Code:
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    
                    Image Img1 = (Image)e.Row.FindControl("Img1");
                    if (e.Row.Cells[7].Text == "Accepted")
                    {
                        Img1.ImageUrl = "~/images/check.ico";
                        Img1.Visible=true;
                    }
                    if (e.Row.Cells[4].Text =="unack")
                    {
                        Img1.ImageUrl = "~/images/warning.ico";
                        Img1.Visible = true;
                    }  
                }
    Last edited by Niheel; May 19 '10, 04:32 PM. Reason: please use code tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What is wrong?
    What you have here looks fine to me...

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Oh wait a sec I think I see.
      Maybe you should be doing this in the OnRowBound event instead of the RowCreated event.

      Comment

      Working...