Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have 3 different images inside one Item Template. Depending upon certain condition, I want to make those visible or invisible. The sample snippet is like

If(condition A== True)
then Img1.visible=true
else if(condition B ==true)
then Img1 and Img2.Visible=True
Else Img1,Img2 and Img3.visible=true.

what should be my code? and where? Any Help or any hint please??
Posted

1 solution

Use gridview's RowDataBound event. Based on the condition set the visibility of the images.

C#
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      Image img1 = (Image)e.Row.FindControl("img1");
      Image img2 = (Image)e.Row.FindControl("img2");
      Image img3 = (Image)e.Row.FindControl("img3");
      // Now check your conditions here..

    }
  }
 
Share this answer
 
Comments
comred 29-Jun-12 2:23am    
If that item template is in 5th column then, how to get that
e.Row.Cells[4].... Which property?
comred 29-Jun-12 2:30am    
Ok I got that... Thank u so much Vani.
Vani Kulkarni 29-Jun-12 2:35am    
Great! It worked for you. Thanks for accepting the solution. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900